signify-ts 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -1
- package/dist/index.d.ts +3 -1
- package/dist/keri/app/accountant.d.ts +10 -0
- package/dist/keri/app/apping.d.ts +1 -0
- package/dist/keri/app/client.d.ts +7 -0
- package/dist/keri/app/habery.d.ts +47 -0
- package/dist/keri/app/signify.d.ts +6 -0
- package/dist/keri/core/authing.d.ts +9 -0
- package/dist/keri/core/cigar.d.ts +3 -3
- package/dist/keri/core/core.d.ts +19 -34
- package/dist/keri/core/counter.d.ts +43 -0
- package/dist/keri/core/eventing.d.ts +21 -0
- package/dist/keri/core/httping.d.ts +34 -0
- package/dist/keri/core/manager.d.ts +38 -17
- package/dist/keri/core/matter.d.ts +23 -1
- package/dist/keri/core/number.d.ts +6 -0
- package/dist/keri/core/prefixer.d.ts +15 -0
- package/dist/keri/core/saider.d.ts +23 -0
- package/dist/keri/core/salter.d.ts +23 -0
- package/dist/keri/core/serder.d.ts +23 -0
- package/dist/keri/core/siger.d.ts +1 -1
- package/dist/keri/core/signer.d.ts +2 -2
- package/dist/keri/core/tholder.d.ts +14 -0
- package/dist/keri/core/utils.d.ts +2 -1
- package/dist/keri/core/verfer.d.ts +12 -0
- package/dist/keri/end/ending.d.ts +13 -0
- package/dist/signify-ts.cjs.development.js +3380 -5
- package/dist/signify-ts.cjs.development.js.map +1 -1
- package/dist/signify-ts.cjs.production.min.js +1 -1
- package/dist/signify-ts.cjs.production.min.js.map +1 -1
- package/dist/signify-ts.esm.js +3365 -5
- package/dist/signify-ts.esm.js.map +1 -1
- package/package.json +4 -2
- package/src/index.ts +5 -6
- package/src/keri/app/accountant.ts +35 -0
- package/src/keri/app/apping.ts +12 -0
- package/src/keri/app/client.ts +30 -0
- package/src/keri/app/habery.ts +152 -0
- package/src/keri/app/signify.ts +12 -0
- package/src/keri/app/tsconfig.json +100 -0
- package/src/keri/core/authing.ts +129 -0
- package/src/keri/core/cigar.ts +4 -4
- package/src/keri/core/core.ts +53 -43
- package/src/keri/core/counter.ts +207 -0
- package/src/keri/core/diger.ts +5 -5
- package/src/keri/core/eventing.ts +219 -0
- package/src/keri/core/httping.ts +163 -0
- package/src/keri/core/indexer.ts +2 -1
- package/src/keri/core/keeping.ts +0 -1
- package/src/keri/core/manager.ts +238 -90
- package/src/keri/core/matter.ts +46 -11
- package/src/keri/core/number.ts +21 -0
- package/src/keri/core/prefixer.ts +212 -0
- package/src/keri/core/saider.ts +158 -0
- package/src/keri/core/salter.ts +9 -5
- package/src/keri/core/serder.ts +99 -0
- package/src/keri/core/siger.ts +2 -2
- package/src/keri/core/signer.ts +4 -3
- package/src/keri/core/tholder.ts +52 -0
- package/src/keri/core/tsconfig.json +2 -2
- package/src/keri/core/utils.ts +10 -6
- package/src/keri/core/verfer.ts +6 -5
- package/src/keri/end/ending.ts +160 -0
- package/src/keri/end/tsconfig.json +100 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import {Codex, Sizage} from "./matter";
|
|
2
|
+
import {b, b64ToInt, d, intToB64} from "./core";
|
|
3
|
+
|
|
4
|
+
export interface CounterArgs {
|
|
5
|
+
code?: string
|
|
6
|
+
count?: number
|
|
7
|
+
countB64?: string
|
|
8
|
+
qb64b?: Uint8Array,
|
|
9
|
+
qb64?: string
|
|
10
|
+
qb2?: Uint8Array
|
|
11
|
+
strip?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class CounterCodex extends Codex {
|
|
15
|
+
public ControllerIdxSigs: string = '-A' // Qualified Base64 Indexed Signature.
|
|
16
|
+
public WitnessIdxSigs: string = '-B' // Qualified Base64 Indexed Signature.
|
|
17
|
+
public NonTransReceiptCouples: string = '-C' // Composed Base64 Couple, pre+cig.
|
|
18
|
+
public TransReceiptQuadruples: string = '-D' // Composed Base64 Quadruple, pre+snu+dig+sig.
|
|
19
|
+
public FirstSeenReplayCouples: string = '-E' // Composed Base64 Couple, fnu+dts.
|
|
20
|
+
public TransIdxSigGroups: string = '-F' // Composed Base64 Group, pre+snu+dig+ControllerIdxSigs group.
|
|
21
|
+
public SealSourceCouples: string = '-G' // Composed Base64 couple, snu+dig of given delegators or issuers event
|
|
22
|
+
public TransLastIdxSigGroups: string = '-H' // Composed Base64 Group, pre+ControllerIdxSigs group.
|
|
23
|
+
public SealSourceTriples: string = '-I' // Composed Base64 triple, pre+snu+dig of anchoring source event
|
|
24
|
+
public SadPathSig: string = '-J' // Composed Base64 Group path+TransIdxSigGroup of SAID of content
|
|
25
|
+
public SadPathSigGroup: string = '-K' // Composed Base64 Group, root(path)+SaidPathCouples
|
|
26
|
+
public PathedMaterialQuadlets: string = '-L' // Composed Grouped Pathed Material Quadlet (4 char each)
|
|
27
|
+
public AttachedMaterialQuadlets: string = '-V' // Composed Grouped Attached Material Quadlet (4 char each)
|
|
28
|
+
public BigAttachedMaterialQuadlets: string = '-0V' // Composed Grouped Attached Material Quadlet (4 char each)
|
|
29
|
+
public KERIProtocolStack: string = '--AAA' // KERI ACDC Protocol Stack CESR Version
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const CtrDex = new CounterCodex()
|
|
33
|
+
|
|
34
|
+
export class Counter {
|
|
35
|
+
static Sizes = new Map(Object.entries({
|
|
36
|
+
'-A': new Sizage(2, 2, 4, 0),
|
|
37
|
+
'-B': new Sizage(2, 2, 4, 0),
|
|
38
|
+
'-C': new Sizage(2, 2, 4, 0),
|
|
39
|
+
'-D': new Sizage(2, 2, 4, 0),
|
|
40
|
+
'-E': new Sizage(2, 2, 4, 0),
|
|
41
|
+
'-F': new Sizage(2, 2, 4, 0),
|
|
42
|
+
'-G': new Sizage(2, 2, 4, 0),
|
|
43
|
+
'-H': new Sizage(2, 2, 4, 0),
|
|
44
|
+
'-I': new Sizage(2, 2, 4, 0),
|
|
45
|
+
'-J': new Sizage(2, 2, 4, 0),
|
|
46
|
+
'-K': new Sizage(2, 2, 4, 0),
|
|
47
|
+
'-L': new Sizage(2, 2, 4, 0),
|
|
48
|
+
'-V': new Sizage(2, 2, 4, 0),
|
|
49
|
+
'-0V': new Sizage(3, 5, 8, 0),
|
|
50
|
+
'--AAA': new Sizage(5, 3, 8, 0),
|
|
51
|
+
}))
|
|
52
|
+
|
|
53
|
+
static Hards = new Map<string, number>([['-A', 2], ['-B', 2], ['-C', 2], ['-D', 2], ['-E', 2], ['-F', 2], ['-G', 2],
|
|
54
|
+
['-H', 2], ['-I', 2], ['-J', 2], ['-K', 2], ['-L', 2], ['-M', 2], ['-N', 2], ['-O', 2], ['-P', 2], ['-Q', 2],
|
|
55
|
+
['-R', 2], ['-S', 2], ['-T', 2], ['-U', 2], ['-V', 2], ['-W', 2], ['-X', 2], ['-Y', 2], ['-Z', 2], ['-a', 2],
|
|
56
|
+
['-b', 2], ['-c', 2], ['-d', 2], ['-e', 2], ['-f', 2], ['-g', 2], ['-h', 2], ['-i', 2], ['-j', 2], ['-k', 2],
|
|
57
|
+
['-l', 2], ['-m', 2], ['-n', 2], ['-o', 2], ['-p', 2], ['-q', 2], ['-r', 2], ['-s', 2], ['-t', 2], ['-u', 2],
|
|
58
|
+
['-v', 2], ['-w', 2], ['-x', 2], ['-y', 2], ['-z', 2], ['-0', 3], ['--', 5]])
|
|
59
|
+
|
|
60
|
+
private _code: string = "";
|
|
61
|
+
private _count: number = -1;
|
|
62
|
+
|
|
63
|
+
constructor({code, count, countB64, qb64b, qb64, qb2}: CounterArgs) {
|
|
64
|
+
if (code != undefined) {
|
|
65
|
+
if (!Counter.Sizes.has(code)) {
|
|
66
|
+
throw new Error(`"Unsupported code=${code}.`)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let sizage = Counter.Sizes.get(code)!
|
|
70
|
+
let cs = sizage.hs + sizage.ss
|
|
71
|
+
if (sizage.fs != cs || cs % 4 != 0) {
|
|
72
|
+
throw new Error(`Whole code size not full size or not multiple of 4. cs=${cs} fs=${sizage.fs}.`)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (count == undefined) {
|
|
76
|
+
count = countB64 == undefined ? 1 : b64ToInt(countB64)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (count < 0 || count > (64 ** sizage.ss - 1)) {
|
|
80
|
+
throw new Error(`Invalid count=${count} for code=${code}.`)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
this._code = code
|
|
84
|
+
this._count = count
|
|
85
|
+
|
|
86
|
+
} else if (qb64b != undefined) {
|
|
87
|
+
let qb64 = d(qb64b)
|
|
88
|
+
this._exfil(qb64)
|
|
89
|
+
} else if (qb64 != undefined) {
|
|
90
|
+
this._exfil(qb64)
|
|
91
|
+
} else if (qb2 != undefined) {
|
|
92
|
+
|
|
93
|
+
} else {
|
|
94
|
+
throw new Error(`Improper initialization need either (code and count) or qb64b or qb64 or qb2.`)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
get code(): string {
|
|
99
|
+
return this._code;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
get count() {
|
|
103
|
+
return this._count;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
get qb64() {
|
|
107
|
+
return this._infil();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
get qb64b() {
|
|
111
|
+
return b(this.qb64)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
countToB64(l?: number): string {
|
|
115
|
+
if (l == undefined) {
|
|
116
|
+
let sizage = Counter.Sizes.get(this.code)!
|
|
117
|
+
l = sizage.ss
|
|
118
|
+
}
|
|
119
|
+
return intToB64(this.count, l)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static semVerToB64(version: string = "", major: number = 0, minor: number = 0, patch: number = 0): string {
|
|
123
|
+
let parts = [major, minor, patch]
|
|
124
|
+
if (version != "") {
|
|
125
|
+
let ssplits = version.split(".")
|
|
126
|
+
let splits = ssplits.map((x) => {
|
|
127
|
+
if (x == "") return 0
|
|
128
|
+
return parseInt(x)
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
let off = splits.length
|
|
132
|
+
let x = 3 - off
|
|
133
|
+
for (let i = 0; i < x; i++) {
|
|
134
|
+
splits.push(parts[i + off])
|
|
135
|
+
}
|
|
136
|
+
parts = splits
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
parts.forEach((p) => {
|
|
140
|
+
if(p < 0 || p > 63) {
|
|
141
|
+
throw new Error(`Out of bounds semantic version. Part=${p} is < 0 or > 63.`)
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
return parts.map((p) => {
|
|
146
|
+
return intToB64(p, 1)
|
|
147
|
+
}).join("")
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private _infil(): string {
|
|
151
|
+
let code = this.code;
|
|
152
|
+
let count = this.count;
|
|
153
|
+
|
|
154
|
+
let sizage = Counter.Sizes.get(code)!;
|
|
155
|
+
let cs = sizage.hs + sizage.ss
|
|
156
|
+
if (sizage.fs != cs || cs % 4 != 0) {
|
|
157
|
+
throw new Error(`Whole code size not full size or not multiple of 4. cs=${cs} fs=${sizage.fs}.`)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (count < 0 || count > (64 ** sizage.ss - 1)) {
|
|
161
|
+
throw new Error(`Invalid count=${count} for code=${code}.`)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
let both = `${code}${intToB64(count, sizage.ss)}`
|
|
165
|
+
|
|
166
|
+
if (both.length % 4) {
|
|
167
|
+
throw new Error(`Invalid size = ${both.length} of ${both} not a multiple of 4.`)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return both
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
private _exfil(qb64: string) {
|
|
174
|
+
if (qb64.length == 0) {
|
|
175
|
+
throw new Error("Empty Material")
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
let first = qb64.slice(0, 2);
|
|
179
|
+
if (!Counter.Hards.has(first)) {
|
|
180
|
+
throw new Error(`Unexpected code ${first}`)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
let hs = Counter.Hards.get(first)!;
|
|
184
|
+
if (qb64.length < hs) {
|
|
185
|
+
throw new Error(`Need ${hs - qb64.length} more characters.`)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
let hard = qb64.slice(0, hs);
|
|
189
|
+
if (!Counter.Sizes.has(hard)) {
|
|
190
|
+
throw new Error(`Unsupported code ${hard}`)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
let sizage = Counter.Sizes.get(hard)!;
|
|
194
|
+
let cs = sizage!.hs + sizage!.ss;
|
|
195
|
+
|
|
196
|
+
if (qb64.length < cs) {
|
|
197
|
+
throw new Error(`Need ${cs - qb64.length} more chars.`)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
let scount = qb64.slice(sizage.hs, sizage.hs + sizage.ss)
|
|
201
|
+
let count = b64ToInt(scount)
|
|
202
|
+
|
|
203
|
+
this._code = hard
|
|
204
|
+
this._count = count
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
}
|
package/src/keri/core/diger.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import {createHash} from "blake3"
|
|
2
|
+
|
|
2
3
|
import {Matter, MatterArgs, MtrDex} from './matter';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -8,7 +9,6 @@ import {Matter, MatterArgs, MtrDex} from './matter';
|
|
|
8
9
|
*
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
|
-
|
|
12
12
|
export class Diger extends Matter {
|
|
13
13
|
private readonly _verify: any
|
|
14
14
|
|
|
@@ -16,13 +16,13 @@ export class Diger extends Matter {
|
|
|
16
16
|
constructor({raw, code = MtrDex.Blake3_256, qb64, qb64b, qb2}: MatterArgs, ser: Uint8Array | null = null) {
|
|
17
17
|
try {
|
|
18
18
|
super({raw, code, qb64, qb64b, qb2});
|
|
19
|
-
} catch (error
|
|
19
|
+
} catch (error) {
|
|
20
20
|
if (ser == null) {
|
|
21
21
|
throw error;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
if (code === MtrDex.Blake3_256) {
|
|
25
|
-
const hasher =
|
|
25
|
+
const hasher = createHash();
|
|
26
26
|
const dig = hasher.update(ser).digest('');
|
|
27
27
|
super({raw: dig, code: code});
|
|
28
28
|
} else {
|
|
@@ -75,7 +75,7 @@ export class Diger extends Matter {
|
|
|
75
75
|
|
|
76
76
|
|
|
77
77
|
blake3_256(ser: Uint8Array, dig: any) {
|
|
78
|
-
const hasher =
|
|
78
|
+
const hasher = createHash();
|
|
79
79
|
let digest = hasher.update(ser).digest('');
|
|
80
80
|
return (digest.toString() === dig.toString());
|
|
81
81
|
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import {b, concat, Dict, Ident, Ilks, Serials, versify, Version, Versionage} from "./core";
|
|
2
|
+
import {Tholder} from "./tholder";
|
|
3
|
+
import {PNumber} from "./number";
|
|
4
|
+
import {Prefixer} from "./prefixer";
|
|
5
|
+
import {Serder} from "./serder";
|
|
6
|
+
import {MtrDex, NonTransDex} from "./matter";
|
|
7
|
+
import {Saider} from "./saider";
|
|
8
|
+
import {Siger} from "./siger";
|
|
9
|
+
import {Cigar} from "./cigar";
|
|
10
|
+
import {Counter, CtrDex} from "./counter";
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
function ample(n: number, f?: number, weak = true) {
|
|
14
|
+
n = Math.max(0, n) // no negatives
|
|
15
|
+
let f1
|
|
16
|
+
if (f == undefined) {
|
|
17
|
+
f1 = Math.max(1, Math.floor(Math.max(0, n - 1) / 3)) // least floor f subject to n >= 3*f+1
|
|
18
|
+
|
|
19
|
+
let f2 = Math.max(1, Math.ceil(Math.max(0, n - 1) / 3)) // most Math.ceil f subject to n >= 3*f+1
|
|
20
|
+
if (weak) { // try both fs to see which one has lowest m
|
|
21
|
+
return Math.min(n, Math.ceil((n + f1 + 1) / 2), Math.ceil((n + f2 + 1) / 2))
|
|
22
|
+
} else {
|
|
23
|
+
return Math.min(n, Math.max(0, n - f1, Math.ceil((n + f1 + 1) / 2)))
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
f = Math.max(0, f)
|
|
27
|
+
let m1 = Math.ceil((n + f + 1) / 2)
|
|
28
|
+
let m2 = Math.max(0, n - f)
|
|
29
|
+
if (m2 < m1 && n > 0) {
|
|
30
|
+
throw new Error(`Invalid f=${f} is too big for n=${n}.`)
|
|
31
|
+
}
|
|
32
|
+
if (weak) {
|
|
33
|
+
return Math.min(n, m1, m2)
|
|
34
|
+
} else {
|
|
35
|
+
return Math.min(n, Math.max(m1, m2))
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface InceptArgs {
|
|
41
|
+
keys: Array<string>,
|
|
42
|
+
isith?: number | string | Array<string>,
|
|
43
|
+
ndigs?: Array<string>,
|
|
44
|
+
nsith?: number | string | Array<string>,
|
|
45
|
+
toad?: number | string,
|
|
46
|
+
wits?: Array<string>,
|
|
47
|
+
cnfg?: Array<string>,
|
|
48
|
+
data?: Array<object>,
|
|
49
|
+
version?: Version,
|
|
50
|
+
kind?: Serials,
|
|
51
|
+
code?: string,
|
|
52
|
+
intive?: boolean
|
|
53
|
+
delpre?: string
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function incept({keys, isith, ndigs, nsith, toad, wits, cnfg, data, version=Versionage, kind=Serials.JSON, code,
|
|
57
|
+
intive = false, delpre}: InceptArgs) {
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
let vs = versify(Ident.KERI, version, kind, 0)
|
|
61
|
+
let ilk = delpre == undefined ? Ilks.icp : Ilks.dip
|
|
62
|
+
let sner = new PNumber(0)
|
|
63
|
+
|
|
64
|
+
if (isith == undefined) {
|
|
65
|
+
isith = Math.max(1, Math.ceil(keys.length / 2))
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let tholder = new Tholder(isith)
|
|
69
|
+
if (tholder.num != undefined && tholder.num < 1) {
|
|
70
|
+
throw new Error(`Invalid sith = ${tholder.num} less than 1.`)
|
|
71
|
+
}
|
|
72
|
+
if (tholder.size > keys.length) {
|
|
73
|
+
throw new Error(`Invalid sith = ${tholder.num} for keys ${keys}`)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (ndigs == undefined) {
|
|
77
|
+
ndigs = new Array<string>()
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (nsith == undefined) {
|
|
81
|
+
nsith = Math.max(0, Math.ceil(ndigs.length / 2))
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let ntholder = new Tholder(nsith)
|
|
85
|
+
if (ntholder.num != undefined && ntholder.num < 0) {
|
|
86
|
+
throw new Error(`Invalid nsith = ${ntholder.num} less than 0.`)
|
|
87
|
+
}
|
|
88
|
+
if (ntholder.size > keys.length) {
|
|
89
|
+
throw new Error(`Invalid nsith = ${ntholder.num} for keys ${ndigs}`)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
wits = wits == undefined ? [] : wits
|
|
93
|
+
if (new Set(wits).size != wits.length) {
|
|
94
|
+
throw new Error(`Invalid wits = ${wits}, has duplicates.`)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (toad == undefined) {
|
|
98
|
+
if (wits.length == 0) {
|
|
99
|
+
toad = 0
|
|
100
|
+
} else {
|
|
101
|
+
toad = ample(wits.length)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let toader = new PNumber(toad)
|
|
106
|
+
if (wits.length > 0) {
|
|
107
|
+
if (toader.num < 1 || toader.num > wits.length) {
|
|
108
|
+
throw new Error(`Invalid toad = ${toader.num} for wits = ${wits}`)
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
if (toader.num != 0) {
|
|
112
|
+
throw new Error(`Invalid toad = ${toader.num} for wits = ${wits}`)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
cnfg = cnfg == undefined ? new Array<string>() : cnfg
|
|
117
|
+
data = data == undefined ? new Array<object>() : data
|
|
118
|
+
|
|
119
|
+
let ked = {
|
|
120
|
+
v: vs,
|
|
121
|
+
t: ilk,
|
|
122
|
+
d: "",
|
|
123
|
+
i: "",
|
|
124
|
+
s: sner.numh,
|
|
125
|
+
kt: (intive && tholder.num != undefined) ? tholder.num : tholder.sith,
|
|
126
|
+
k: keys,
|
|
127
|
+
nt: (intive && tholder.num != undefined) ? ntholder.num: ntholder.sith,
|
|
128
|
+
n: ndigs,
|
|
129
|
+
bt: intive ? toader.num : toader.numh,
|
|
130
|
+
b: wits,
|
|
131
|
+
c: cnfg,
|
|
132
|
+
a: data
|
|
133
|
+
} as Dict<any>
|
|
134
|
+
|
|
135
|
+
if (delpre != undefined) {
|
|
136
|
+
ked["di"] = delpre
|
|
137
|
+
if (code == undefined) {
|
|
138
|
+
code = MtrDex.Blake3_256
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
let prefixer
|
|
143
|
+
if (delpre == undefined && code == undefined && keys.length == 1) {
|
|
144
|
+
prefixer = new Prefixer({qb64: keys[0]})
|
|
145
|
+
if (prefixer.digestive) {
|
|
146
|
+
throw new Error(`Invalid code, digestive=${prefixer.code}, must be derived from ked.`)
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
prefixer = new Prefixer({code: code}, ked)
|
|
150
|
+
if (delpre != undefined) {
|
|
151
|
+
if(!prefixer.digestive) {
|
|
152
|
+
throw new Error(`Invalid derivation code = ${prefixer.code} for delegation. Must be digestive`)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
ked["i"] = prefixer.qb64
|
|
158
|
+
if (prefixer.digestive) {
|
|
159
|
+
ked["d"] = prefixer.qb64
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
[, ked] = Saider.saidify(ked)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return new Serder(ked)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function messagize(serder: Serder, sigers?: Array<Siger>, seal?: any, wigers?:Array<Cigar>, cigars?:Array<Cigar>,
|
|
169
|
+
pipelined:boolean = false): Uint8Array {
|
|
170
|
+
let msg = new Uint8Array(b(serder.raw))
|
|
171
|
+
let atc = new Uint8Array()
|
|
172
|
+
|
|
173
|
+
if (sigers == undefined && wigers == undefined && cigars == undefined) {
|
|
174
|
+
throw new Error(`Missing attached signatures on message = ${serder.ked}.`)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (sigers != undefined) {
|
|
178
|
+
if (seal != undefined) {
|
|
179
|
+
throw new Error(`Index sig group seals not yet supported`)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
atc = concat(atc, new Counter({code: CtrDex.ControllerIdxSigs, count: sigers.length}).qb64b)
|
|
183
|
+
sigers.forEach((siger) => {
|
|
184
|
+
atc = concat(atc, siger.qb64b)
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (wigers != undefined) {
|
|
189
|
+
atc = concat(atc, new Counter({code: CtrDex.ControllerIdxSigs, count: wigers.length}).qb64b)
|
|
190
|
+
|
|
191
|
+
wigers.forEach((wiger) => {
|
|
192
|
+
if (wiger.verfer && !(wiger.verfer.code in NonTransDex)) {
|
|
193
|
+
throw new Error(`Attempt to use tranferable prefix=${wiger.verfer.qb64} for receipt.`)
|
|
194
|
+
}
|
|
195
|
+
atc = concat(atc, wiger.qb64b)
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (cigars != undefined) {
|
|
200
|
+
atc = concat(atc, new Counter({code: CtrDex.ControllerIdxSigs, count: cigars.length}).qb64b)
|
|
201
|
+
|
|
202
|
+
cigars.forEach((cigar) => {
|
|
203
|
+
if (cigar.verfer && !(cigar.verfer.code in NonTransDex)) {
|
|
204
|
+
throw new Error(`Attempt to use tranferable prefix=${cigar.verfer.qb64} for receipt.`)
|
|
205
|
+
}
|
|
206
|
+
atc = concat(atc, cigar.qb64b)
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (pipelined) {
|
|
211
|
+
if (atc.length % 4 != 0) {
|
|
212
|
+
throw new Error(`Invalid attachments size=${atc.length}, nonintegral quadlets.`)
|
|
213
|
+
}
|
|
214
|
+
msg = concat(msg, new Counter({code: CtrDex.AttachedMaterialQuadlets, count: (Math.floor(atc.length / 4))}).qb64b)
|
|
215
|
+
}
|
|
216
|
+
msg = concat(msg, atc)
|
|
217
|
+
|
|
218
|
+
return msg
|
|
219
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import {serializeDictionary, Dictionary, parseDictionary, Item, Parameters} from "structured-headers";
|
|
2
|
+
import {Signer} from "./signer";
|
|
3
|
+
import {b} from "./core";
|
|
4
|
+
import {Cigar} from "./cigar";
|
|
5
|
+
import {nowUTC} from "./utils";
|
|
6
|
+
import {Siger} from "./siger";
|
|
7
|
+
import Base64 from "urlsafe-base64"
|
|
8
|
+
import { Buffer } from 'buffer';
|
|
9
|
+
|
|
10
|
+
export function normalize(header: string) {
|
|
11
|
+
return header.trim()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface SiginputArgs {
|
|
15
|
+
name: string,
|
|
16
|
+
method:string,
|
|
17
|
+
path:string,
|
|
18
|
+
headers: Headers,
|
|
19
|
+
fields: Array<string>,
|
|
20
|
+
expires?:number,
|
|
21
|
+
nonce?: string,
|
|
22
|
+
alg?: string,
|
|
23
|
+
keyid?: string,
|
|
24
|
+
context?: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function siginput(signer: Signer,
|
|
28
|
+
{name, method, path, headers, fields,
|
|
29
|
+
expires, nonce, alg, keyid, context}: SiginputArgs): [Map<string, string>, Siger|Cigar] {
|
|
30
|
+
|
|
31
|
+
let items = new Array<string>()
|
|
32
|
+
let ifields = new Array<[string, Map<string, string>]>()
|
|
33
|
+
|
|
34
|
+
fields.forEach((field) => {
|
|
35
|
+
if (field.startsWith("@")) {
|
|
36
|
+
switch (field) {
|
|
37
|
+
case "@method":
|
|
38
|
+
items.push(`"${field}": ${method}`)
|
|
39
|
+
ifields.push([field, new Map()])
|
|
40
|
+
break
|
|
41
|
+
case "@path":
|
|
42
|
+
items.push(`"${field}": ${path}`)
|
|
43
|
+
ifields.push([field, new Map()])
|
|
44
|
+
break
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
if (!headers.has(field))
|
|
48
|
+
return
|
|
49
|
+
|
|
50
|
+
ifields.push([field, new Map()])
|
|
51
|
+
let value = normalize(headers.get(field)!)
|
|
52
|
+
items.push(`"${field}": ${value}`)
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
let nameParams = new Map<string, string|number>()
|
|
57
|
+
let now = Math.floor(nowUTC().getTime() / 1000)
|
|
58
|
+
nameParams.set("created", now)
|
|
59
|
+
|
|
60
|
+
let values = [`(${ifields.join(" ")})`, `created=${now}`]
|
|
61
|
+
if (expires != undefined) {
|
|
62
|
+
values.push(`expires=${expires}`)
|
|
63
|
+
nameParams.set('expires', expires)
|
|
64
|
+
}
|
|
65
|
+
if (nonce != undefined) {
|
|
66
|
+
values.push(`nonce=${nonce}`)
|
|
67
|
+
nameParams.set('nonce', nonce)
|
|
68
|
+
}
|
|
69
|
+
if (keyid != undefined) {
|
|
70
|
+
values.push(`keyid=${keyid}`)
|
|
71
|
+
nameParams.set('keyid', keyid)
|
|
72
|
+
}
|
|
73
|
+
if (context != undefined) {
|
|
74
|
+
values.push(`context=${context}`)
|
|
75
|
+
nameParams.set('context', context)
|
|
76
|
+
}
|
|
77
|
+
if (alg != undefined) {
|
|
78
|
+
values.push(`alg=${alg}`)
|
|
79
|
+
nameParams.set('alg', alg)
|
|
80
|
+
}
|
|
81
|
+
let sid = new Map([
|
|
82
|
+
[name, [ifields, nameParams]]
|
|
83
|
+
])
|
|
84
|
+
|
|
85
|
+
let params = values.join(";")
|
|
86
|
+
items.push(`"@signature-params: ${params}"`)
|
|
87
|
+
|
|
88
|
+
let ser = items.join("\n")
|
|
89
|
+
let sig = signer.sign(b(ser))
|
|
90
|
+
|
|
91
|
+
return [new Map<string, string>([['Signature-Input', `${serializeDictionary(sid as Dictionary)}`]]), sig]
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export class Unqualified {
|
|
95
|
+
private readonly _raw: Uint8Array
|
|
96
|
+
|
|
97
|
+
constructor(raw: Uint8Array) {
|
|
98
|
+
this._raw = raw
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
get qb64(): string {
|
|
102
|
+
return Base64.encode(Buffer.from(this._raw))
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
get qb64b(): Uint8Array {
|
|
106
|
+
return b(this.qb64)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export class Inputage {
|
|
111
|
+
public name: any
|
|
112
|
+
public fields: any
|
|
113
|
+
public created: any
|
|
114
|
+
public expires: any
|
|
115
|
+
public nonce: any
|
|
116
|
+
public alg: any
|
|
117
|
+
public keyid: any
|
|
118
|
+
public context: any
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function desiginput(value: string): Array<Inputage> {
|
|
122
|
+
let sid = parseDictionary(value)
|
|
123
|
+
let siginputs = new Array<Inputage>()
|
|
124
|
+
|
|
125
|
+
sid.forEach((value, key) => {
|
|
126
|
+
let siginput = new Inputage()
|
|
127
|
+
siginput.name = key
|
|
128
|
+
let list: Item[]
|
|
129
|
+
let params
|
|
130
|
+
[list, params] = value as [Item[], Parameters]
|
|
131
|
+
siginput.fields = list.map((item) => item[0])
|
|
132
|
+
|
|
133
|
+
if (!params.has("created")) {
|
|
134
|
+
throw new Error("missing required `created` field from signature input")
|
|
135
|
+
}
|
|
136
|
+
siginput.created = params.get("created")
|
|
137
|
+
|
|
138
|
+
if (params.has("expires")) {
|
|
139
|
+
siginput.expires = params.get("expires")
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (params.has("nonce")) {
|
|
143
|
+
siginput.nonce = params.get("nonce")
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (params.has("alg")) {
|
|
147
|
+
siginput.alg = params.get("alg")
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (params.has("keyid")) {
|
|
151
|
+
siginput.keyid = params.get("keyid")
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (params.has("context")) {
|
|
155
|
+
siginput.context = params.get("context")
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
siginputs.push(siginput)
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
return siginputs
|
|
162
|
+
|
|
163
|
+
}
|
package/src/keri/core/indexer.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {EmptyMaterialError} from "./kering";
|
|
2
2
|
import {b, b64ToInt, d, intToB64, readInt} from "./core";
|
|
3
|
-
|
|
3
|
+
import Base64 from "urlsafe-base64"
|
|
4
|
+
import { Buffer } from 'buffer';
|
|
4
5
|
|
|
5
6
|
export class IndexerCodex {
|
|
6
7
|
Ed25519_Sig: string = 'A' // Ed25519 sig appears same in both lists if any.
|