generated from jasonkuhrt/template-typescript-lib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.spec.ts
153 lines (137 loc) · 4.96 KB
/
index.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import { beforeEach, describe, expect, it } from 'vitest'
import * as Lib from './index.js'
import { SAIDDex, Serials } from './index.js'
describe('saidify function tests', () => {
let data: any
let label: string
let code: string
let kind: Serials
beforeEach(() => {
data = {
d: ``,
attr1: `value1`,
attr2: `value2`,
attr3: `value3`,
}
code = SAIDDex.Blake3_256
kind = Serials.JSON
label = `d`
})
it(`produces a valid SAID for Blake3-256 algo and JSON serialization with only a data arg`, () => {
const [said, _sad] = Lib.saidify(data)
expect(said).toEqual(`EHSOlNZzwiekacJenXM3qPNU9-07ic_G0ejn8hrA2lKQ`)
})
it(`produces a valid SAID for Blake3-256 and JSON with data and code arg`, () => {
const [said, _sad] = Lib.saidify(data, 'd', code)
expect(said).toEqual(`EHSOlNZzwiekacJenXM3qPNU9-07ic_G0ejn8hrA2lKQ`)
})
it(`produces a valid SAID for Blake3-256 and JSON with data and kind arg`, () => {
const [said, _sad] = Lib.saidify(data, 'd', code, kind)
expect(said).toEqual(`EHSOlNZzwiekacJenXM3qPNU9-07ic_G0ejn8hrA2lKQ`)
})
it(`produces a valid SAID for Blake3-256 and JSON with data, code, kind, and label arg`, () => {
const [said, _sad] = Lib.saidify(data, label, code, kind)
expect(said).toEqual(`EHSOlNZzwiekacJenXM3qPNU9-07ic_G0ejn8hrA2lKQ`)
})
it(`produces a valid SAID for Blake2b-256 and JSON with data, code, kind, and label arg`, () => {
const [said, _sad] = Lib.saidify(data, label, code = SAIDDex.Blake2b_256, kind)
expect(said).toEqual(`FIzy6Co4x-ynSoF7syuL15Vf82PxldUz05iTGPqiG31u`)
})
it(`produces a valid SAID for SHA2-256 and JSON with data, code, kind, and label arg`, () => {
const [said, _sad] = Lib.saidify(data, label, code = SAIDDex.SHA2_256, kind)
expect(said).toEqual(`IOwKVs_pD6kKKw1_eHXI4CUfRfw4mBpvlUuIDdZQXoPr`)
})
it(`produces a valid SAID for SHA3-256 and JSON with data, code, kind, and label arg`, () => {
const [said, _sad] = Lib.saidify(data, label, code = SAIDDex.SHA3_256, kind)
expect(said).toEqual(`HLL3GkCKe6HnqkP4ENBWjLlAQVR6Agsw7TVNToyn0lk3`)
})
})
describe('example code tests', () => {
it(`README and JSDoc code test`, () => {
const data = {
a: 1,
b: 2,
d: '',
}
const label = 'd'
const [said, _sad] = Lib.saidify(data, label, SAIDDex.Blake3_256, Serials.JSON)
expect(said).toEqual('ELLbizIr2FJLHexNkiLZpsTWfhwUmZUicuhmoZ9049Hz')
})
})
describe(`verify function tests`, () => {
it(`should verify when only self-addressing data structure passed in`, () => {
const data = {
a: 1,
b: 2,
d: 'ELLbizIr2FJLHexNkiLZpsTWfhwUmZUicuhmoZ9049Hz',
}
const doesVerify = Lib.verify(data)
expect(doesVerify).toEqual(true)
})
it(`should verify self-addressing data against the SAID`, () => {
const said = 'ELLbizIr2FJLHexNkiLZpsTWfhwUmZUicuhmoZ9049Hz'
const data = {
a: 1,
b: 2,
d: 'ELLbizIr2FJLHexNkiLZpsTWfhwUmZUicuhmoZ9049Hz',
}
const doesVerify = Lib.verify(data, said)
expect(doesVerify).toEqual(true)
})
it(`should verify a self-addressing data structure and it's labeled SAID field against a SAID`, () => {
const said = 'ELLbizIr2FJLHexNkiLZpsTWfhwUmZUicuhmoZ9049Hz'
const data = {
a: 1,
b: 2,
d: 'ELLbizIr2FJLHexNkiLZpsTWfhwUmZUicuhmoZ9049Hz',
}
const label = 'd'
const doesVerify = Lib.verify(data, said, label)
expect(doesVerify).toEqual(true)
})
it(`Blake2b-256 SAID matches KERIpy`, () => {
const keripySAID = 'FOZ5T-PCxuMDMkl-Vih1BAWcxox5OcclLaxtTcmZcYmr' // got from from KERIpy
const data = {
d: '',
first: 'Sue',
last: 'Smith',
role: 'Founder',
}
const label = 'd'
const code = SAIDDex.Blake2b_256
const [newSaid, sadData] = Lib.saidify(data, label, code, Serials.JSON)
expect(newSaid).toEqual(keripySAID)
const doesVerify = Lib.verify(sadData, newSaid, label, code)
expect(doesVerify).toEqual(true)
})
it(`SHA2-256 SAID matches KERIpy`, () => {
const keripySAID = 'IFvJUGAb-3CR_i-34QIg0qJ12-Dnq27pDdgEo3icRdM1' // got from from KERIpy
const data = {
d: '',
first: 'Sue',
last: 'Smith',
role: 'Founder',
}
const label = 'd'
const code = SAIDDex.SHA2_256
const [newSaid, sadData] = Lib.saidify(data, label, code, Serials.JSON)
expect(newSaid).toEqual(keripySAID)
const doesVerify = Lib.verify(sadData, newSaid, label, code)
expect(doesVerify).toEqual(true)
})
it(`SHA3-256 SAID matches KERIpy`, () => {
const keripySAID = 'HGQJ4vetZJ_DfufKM0YcTyBXHlR3LxHRu-tOckDHTDM3' // got from from KERIpy
const data = {
d: '',
first: 'Sue',
last: 'Smith',
role: 'Founder',
}
const label = 'd'
const code = SAIDDex.SHA3_256
const [newSaid, sadData] = Lib.saidify(data, label, code, Serials.JSON)
expect(newSaid).toEqual(keripySAID)
const doesVerify = Lib.verify(sadData, newSaid, label, code)
expect(doesVerify).toEqual(true)
})
})