signify-ts 0.1.1 → 0.2.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.
Files changed (115) hide show
  1. package/README.md +96 -47
  2. package/dist/buffer-polyfill.d.ts +1 -0
  3. package/dist/exports.d.ts +40 -0
  4. package/dist/index.d.ts +4 -3
  5. package/dist/keri/app/aiding.d.ts +138 -0
  6. package/dist/keri/app/clienting.d.ts +182 -0
  7. package/dist/keri/app/contacting.d.ts +93 -0
  8. package/dist/keri/app/controller.d.ts +49 -0
  9. package/dist/keri/app/coring.d.ts +121 -0
  10. package/dist/keri/app/credentialing.d.ts +245 -0
  11. package/dist/keri/app/escrowing.d.ts +19 -0
  12. package/dist/keri/app/exchanging.d.ts +60 -0
  13. package/dist/keri/app/grouping.d.ts +44 -0
  14. package/dist/keri/app/habery.d.ts +48 -47
  15. package/dist/keri/app/notifying.d.ts +34 -0
  16. package/dist/keri/core/authing.d.ts +10 -9
  17. package/dist/keri/core/bexter.d.ts +7 -0
  18. package/dist/keri/core/cigar.d.ts +8 -8
  19. package/dist/keri/core/cipher.d.ts +5 -5
  20. package/dist/keri/core/core.d.ts +59 -53
  21. package/dist/keri/core/counter.d.ts +43 -43
  22. package/dist/keri/core/decrypter.d.ts +10 -10
  23. package/dist/keri/core/diger.d.ts +21 -21
  24. package/dist/keri/core/encrypter.d.ts +9 -9
  25. package/dist/keri/core/eventing.d.ts +54 -21
  26. package/dist/keri/core/httping.d.ts +44 -34
  27. package/dist/keri/core/indexer.d.ts +98 -88
  28. package/dist/keri/core/keeping.d.ts +103 -1
  29. package/dist/keri/core/kering.d.ts +5 -5
  30. package/dist/keri/core/manager.d.ts +174 -172
  31. package/dist/keri/core/matter.d.ts +116 -69
  32. package/dist/keri/core/number.d.ts +7 -6
  33. package/dist/keri/core/pather.d.ts +7 -0
  34. package/dist/keri/core/prefixer.d.ts +15 -15
  35. package/dist/keri/core/saider.d.ts +23 -23
  36. package/dist/keri/core/salter.d.ts +23 -23
  37. package/dist/keri/core/seqner.d.ts +15 -0
  38. package/dist/keri/core/serder.d.ts +31 -23
  39. package/dist/keri/core/siger.d.ts +18 -18
  40. package/dist/keri/core/signer.d.ts +34 -34
  41. package/dist/keri/core/tholder.d.ts +29 -14
  42. package/dist/keri/core/utils.d.ts +20 -15
  43. package/dist/keri/core/vdring.d.ts +16 -0
  44. package/dist/keri/core/verfer.d.ts +13 -12
  45. package/dist/keri/end/ending.d.ts +13 -13
  46. package/dist/math.d.ts +1 -0
  47. package/dist/ready.d.ts +1 -0
  48. package/dist/signify-ts.cjs +7842 -0
  49. package/dist/signify-ts.cjs.development.js +6369 -256
  50. package/dist/signify-ts.cjs.development.js.map +1 -1
  51. package/dist/signify-ts.cjs.map +7 -0
  52. package/dist/signify-ts.cjs.production.min.js +1 -1
  53. package/dist/signify-ts.cjs.production.min.js.map +1 -1
  54. package/dist/signify-ts.esm.js +6205 -229
  55. package/dist/signify-ts.esm.js.map +1 -1
  56. package/dist/signify-ts.mjs +7818 -0
  57. package/dist/signify-ts.mjs.map +7 -0
  58. package/package.json +49 -49
  59. package/src/buffer-polyfill.ts +5 -0
  60. package/src/exports.ts +44 -0
  61. package/src/index.ts +4 -5
  62. package/src/keri/app/aiding.ts +493 -0
  63. package/src/keri/app/clienting.ts +492 -0
  64. package/src/keri/app/contacting.ts +188 -0
  65. package/src/keri/app/controller.ts +372 -0
  66. package/src/keri/app/coring.ts +225 -0
  67. package/src/keri/app/credentialing.ts +841 -0
  68. package/src/keri/app/escrowing.ts +34 -0
  69. package/src/keri/app/exchanging.ts +220 -0
  70. package/src/keri/app/grouping.ts +90 -0
  71. package/src/keri/app/habery.ts +118 -85
  72. package/src/keri/app/notifying.ts +69 -0
  73. package/src/keri/core/authing.ts +73 -85
  74. package/src/keri/core/bexter.ts +138 -0
  75. package/src/keri/core/cigar.ts +10 -11
  76. package/src/keri/core/cipher.ts +23 -14
  77. package/src/keri/core/core.ts +223 -81
  78. package/src/keri/core/counter.ts +182 -116
  79. package/src/keri/core/decrypter.ts +48 -34
  80. package/src/keri/core/diger.ts +23 -22
  81. package/src/keri/core/encrypter.ts +37 -27
  82. package/src/keri/core/eventing.ts +468 -106
  83. package/src/keri/core/httping.ts +151 -105
  84. package/src/keri/core/indexer.ts +313 -211
  85. package/src/keri/core/keeping.ts +679 -3
  86. package/src/keri/core/kering.ts +4 -6
  87. package/src/keri/core/manager.ts +660 -499
  88. package/src/keri/core/matter.ts +382 -148
  89. package/src/keri/core/number.ts +56 -11
  90. package/src/keri/core/pather.ts +98 -0
  91. package/src/keri/core/prefixer.ts +122 -101
  92. package/src/keri/core/saider.ts +104 -76
  93. package/src/keri/core/salter.ts +71 -40
  94. package/src/keri/core/seqner.ts +46 -0
  95. package/src/keri/core/serder.ts +102 -38
  96. package/src/keri/core/siger.ts +19 -18
  97. package/src/keri/core/signer.ts +73 -53
  98. package/src/keri/core/tholder.ts +196 -30
  99. package/src/keri/core/utils.ts +121 -50
  100. package/src/keri/core/vdring.ts +94 -0
  101. package/src/keri/core/verfer.ts +22 -9
  102. package/src/keri/end/ending.ts +111 -101
  103. package/src/math.ts +3 -0
  104. package/src/ready.ts +5 -0
  105. package/dist/keri/app/accountant.d.ts +0 -10
  106. package/dist/keri/app/apping.d.ts +0 -1
  107. package/dist/keri/app/client.d.ts +0 -7
  108. package/dist/keri/app/signify.d.ts +0 -6
  109. package/src/keri/app/accountant.ts +0 -35
  110. package/src/keri/app/apping.ts +0 -12
  111. package/src/keri/app/client.ts +0 -30
  112. package/src/keri/app/signify.ts +0 -12
  113. package/src/keri/app/tsconfig.json +0 -100
  114. package/src/keri/core/tsconfig.json +0 -100
  115. package/src/keri/end/tsconfig.json +0 -100
@@ -1,97 +1,151 @@
1
- import {Codex, Sizage} from "./matter";
2
- import {b, b64ToInt, d, intToB64} from "./core";
1
+ import { Codex, Sizage } from './matter';
2
+ import { b, b64ToInt, d, intToB64 } from './core';
3
3
 
4
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
5
+ code?: string;
6
+ count?: number;
7
+ countB64?: string;
8
+ qb64b?: Uint8Array;
9
+ qb64?: string;
10
+ qb2?: Uint8Array;
11
+ strip?: boolean;
12
12
  }
13
13
 
14
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
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
30
  }
31
31
 
32
- export const CtrDex = new CounterCodex()
32
+ export const CtrDex = new CounterCodex();
33
33
 
34
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 = "";
35
+ static Sizes = new Map(
36
+ Object.entries({
37
+ '-A': new Sizage(2, 2, 4, 0),
38
+ '-B': new Sizage(2, 2, 4, 0),
39
+ '-C': new Sizage(2, 2, 4, 0),
40
+ '-D': new Sizage(2, 2, 4, 0),
41
+ '-E': new Sizage(2, 2, 4, 0),
42
+ '-F': new Sizage(2, 2, 4, 0),
43
+ '-G': new Sizage(2, 2, 4, 0),
44
+ '-H': new Sizage(2, 2, 4, 0),
45
+ '-I': new Sizage(2, 2, 4, 0),
46
+ '-J': new Sizage(2, 2, 4, 0),
47
+ '-K': new Sizage(2, 2, 4, 0),
48
+ '-L': new Sizage(2, 2, 4, 0),
49
+ '-V': new Sizage(2, 2, 4, 0),
50
+ '-0V': new Sizage(3, 5, 8, 0),
51
+ '--AAA': new Sizage(5, 3, 8, 0),
52
+ })
53
+ );
54
+
55
+ static Hards = new Map<string, number>([
56
+ ['-A', 2],
57
+ ['-B', 2],
58
+ ['-C', 2],
59
+ ['-D', 2],
60
+ ['-E', 2],
61
+ ['-F', 2],
62
+ ['-G', 2],
63
+ ['-H', 2],
64
+ ['-I', 2],
65
+ ['-J', 2],
66
+ ['-K', 2],
67
+ ['-L', 2],
68
+ ['-M', 2],
69
+ ['-N', 2],
70
+ ['-O', 2],
71
+ ['-P', 2],
72
+ ['-Q', 2],
73
+ ['-R', 2],
74
+ ['-S', 2],
75
+ ['-T', 2],
76
+ ['-U', 2],
77
+ ['-V', 2],
78
+ ['-W', 2],
79
+ ['-X', 2],
80
+ ['-Y', 2],
81
+ ['-Z', 2],
82
+ ['-a', 2],
83
+ ['-b', 2],
84
+ ['-c', 2],
85
+ ['-d', 2],
86
+ ['-e', 2],
87
+ ['-f', 2],
88
+ ['-g', 2],
89
+ ['-h', 2],
90
+ ['-i', 2],
91
+ ['-j', 2],
92
+ ['-k', 2],
93
+ ['-l', 2],
94
+ ['-m', 2],
95
+ ['-n', 2],
96
+ ['-o', 2],
97
+ ['-p', 2],
98
+ ['-q', 2],
99
+ ['-r', 2],
100
+ ['-s', 2],
101
+ ['-t', 2],
102
+ ['-u', 2],
103
+ ['-v', 2],
104
+ ['-w', 2],
105
+ ['-x', 2],
106
+ ['-y', 2],
107
+ ['-z', 2],
108
+ ['-0', 3],
109
+ ['--', 5],
110
+ ]);
111
+
112
+ private _code: string = '';
61
113
  private _count: number = -1;
62
114
 
63
- constructor({code, count, countB64, qb64b, qb64, qb2}: CounterArgs) {
115
+ constructor({ code, count, countB64, qb64b, qb64, qb2 }: CounterArgs) {
64
116
  if (code != undefined) {
65
117
  if (!Counter.Sizes.has(code)) {
66
- throw new Error(`"Unsupported code=${code}.`)
118
+ throw new Error(`"Unsupported code=${code}.`);
67
119
  }
68
120
 
69
- let sizage = Counter.Sizes.get(code)!
70
- let cs = sizage.hs + sizage.ss
121
+ const sizage = Counter.Sizes.get(code)!;
122
+ const cs = sizage.hs + sizage.ss;
71
123
  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}.`)
124
+ throw new Error(
125
+ `Whole code size not full size or not multiple of 4. cs=${cs} fs=${sizage.fs}.`
126
+ );
73
127
  }
74
128
 
75
129
  if (count == undefined) {
76
- count = countB64 == undefined ? 1 : b64ToInt(countB64)
130
+ count = countB64 == undefined ? 1 : b64ToInt(countB64);
77
131
  }
78
132
 
79
- if (count < 0 || count > (64 ** sizage.ss - 1)) {
80
- throw new Error(`Invalid count=${count} for code=${code}.`)
133
+ if (count < 0 || count > 64 ** sizage.ss - 1) {
134
+ throw new Error(`Invalid count=${count} for code=${code}.`);
81
135
  }
82
136
 
83
- this._code = code
84
- this._count = count
85
-
137
+ this._code = code;
138
+ this._count = count;
86
139
  } else if (qb64b != undefined) {
87
- let qb64 = d(qb64b)
88
- this._exfil(qb64)
140
+ const qb64 = d(qb64b);
141
+ this._exfil(qb64);
89
142
  } else if (qb64 != undefined) {
90
- this._exfil(qb64)
143
+ this._exfil(qb64);
91
144
  } else if (qb2 != undefined) {
92
-
93
145
  } else {
94
- throw new Error(`Improper initialization need either (code and count) or qb64b or qb64 or qb2.`)
146
+ throw new Error(
147
+ `Improper initialization need either (code and count) or qb64b or qb64 or qb2.`
148
+ );
95
149
  }
96
150
  }
97
151
 
@@ -108,100 +162,112 @@ export class Counter {
108
162
  }
109
163
 
110
164
  get qb64b() {
111
- return b(this.qb64)
165
+ return b(this.qb64);
112
166
  }
113
167
 
114
168
  countToB64(l?: number): string {
115
169
  if (l == undefined) {
116
- let sizage = Counter.Sizes.get(this.code)!
117
- l = sizage.ss
170
+ const sizage = Counter.Sizes.get(this.code)!;
171
+ l = sizage.ss;
118
172
  }
119
- return intToB64(this.count, l)
173
+ return intToB64(this.count, l);
120
174
  }
121
175
 
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
176
+ static semVerToB64(
177
+ version: string = '',
178
+ major: number = 0,
179
+ minor: number = 0,
180
+ patch: number = 0
181
+ ): string {
182
+ let parts = [major, minor, patch];
183
+ if (version != '') {
184
+ const ssplits = version.split('.');
185
+ const splits = ssplits.map((x) => {
186
+ if (x == '') return 0;
187
+ return parseInt(x);
188
+ });
189
+
190
+ const off = splits.length;
191
+ const x = 3 - off;
133
192
  for (let i = 0; i < x; i++) {
134
- splits.push(parts[i + off])
193
+ splits.push(parts[i + off]);
135
194
  }
136
- parts = splits
195
+ parts = splits;
137
196
  }
138
197
 
139
198
  parts.forEach((p) => {
140
- if(p < 0 || p > 63) {
141
- throw new Error(`Out of bounds semantic version. Part=${p} is < 0 or > 63.`)
199
+ if (p < 0 || p > 63) {
200
+ throw new Error(
201
+ `Out of bounds semantic version. Part=${p} is < 0 or > 63.`
202
+ );
142
203
  }
143
- })
204
+ });
144
205
 
145
- return parts.map((p) => {
146
- return intToB64(p, 1)
147
- }).join("")
206
+ return parts
207
+ .map((p) => {
208
+ return intToB64(p, 1);
209
+ })
210
+ .join('');
148
211
  }
149
212
 
150
213
  private _infil(): string {
151
- let code = this.code;
152
- let count = this.count;
214
+ const code = this.code;
215
+ const count = this.count;
153
216
 
154
- let sizage = Counter.Sizes.get(code)!;
155
- let cs = sizage.hs + sizage.ss
217
+ const sizage = Counter.Sizes.get(code)!;
218
+ const cs = sizage.hs + sizage.ss;
156
219
  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}.`)
220
+ throw new Error(
221
+ `Whole code size not full size or not multiple of 4. cs=${cs} fs=${sizage.fs}.`
222
+ );
158
223
  }
159
224
 
160
- if (count < 0 || count > (64 ** sizage.ss - 1)) {
161
- throw new Error(`Invalid count=${count} for code=${code}.`)
225
+ if (count < 0 || count > 64 ** sizage.ss - 1) {
226
+ throw new Error(`Invalid count=${count} for code=${code}.`);
162
227
  }
163
228
 
164
- let both = `${code}${intToB64(count, sizage.ss)}`
229
+ const both = `${code}${intToB64(count, sizage.ss)}`;
165
230
 
166
231
  if (both.length % 4) {
167
- throw new Error(`Invalid size = ${both.length} of ${both} not a multiple of 4.`)
232
+ throw new Error(
233
+ `Invalid size = ${both.length} of ${both} not a multiple of 4.`
234
+ );
168
235
  }
169
236
 
170
- return both
237
+ return both;
171
238
  }
172
239
 
173
240
  private _exfil(qb64: string) {
174
241
  if (qb64.length == 0) {
175
- throw new Error("Empty Material")
242
+ throw new Error('Empty Material');
176
243
  }
177
244
 
178
- let first = qb64.slice(0, 2);
245
+ const first = qb64.slice(0, 2);
179
246
  if (!Counter.Hards.has(first)) {
180
- throw new Error(`Unexpected code ${first}`)
247
+ throw new Error(`Unexpected code ${first}`);
181
248
  }
182
249
 
183
- let hs = Counter.Hards.get(first)!;
250
+ const hs = Counter.Hards.get(first)!;
184
251
  if (qb64.length < hs) {
185
- throw new Error(`Need ${hs - qb64.length} more characters.`)
252
+ throw new Error(`Need ${hs - qb64.length} more characters.`);
186
253
  }
187
254
 
188
- let hard = qb64.slice(0, hs);
255
+ const hard = qb64.slice(0, hs);
189
256
  if (!Counter.Sizes.has(hard)) {
190
- throw new Error(`Unsupported code ${hard}`)
257
+ throw new Error(`Unsupported code ${hard}`);
191
258
  }
192
259
 
193
- let sizage = Counter.Sizes.get(hard)!;
194
- let cs = sizage!.hs + sizage!.ss;
260
+ const sizage = Counter.Sizes.get(hard)!;
261
+ const cs = sizage!.hs + sizage!.ss;
195
262
 
196
263
  if (qb64.length < cs) {
197
- throw new Error(`Need ${cs - qb64.length} more chars.`)
264
+ throw new Error(`Need ${cs - qb64.length} more chars.`);
198
265
  }
199
266
 
200
- let scount = qb64.slice(sizage.hs, sizage.hs + sizage.ss)
201
- let count = b64ToInt(scount)
267
+ const scount = qb64.slice(sizage.hs, sizage.hs + sizage.ss);
268
+ const count = b64ToInt(scount);
202
269
 
203
- this._code = hard
204
- this._count = count
270
+ this._code = hard;
271
+ this._count = count;
205
272
  }
206
-
207
- }
273
+ }
@@ -1,66 +1,80 @@
1
- import libsodium from "libsodium-wrappers-sumo";
2
-
3
- import {Matter, MatterArgs, MtrDex} from './matter';
4
- import {Signer} from "./signer";
5
- import {Cipher} from "./cipher";
6
- import {EmptyMaterialError} from "./kering";
7
- import {Salter} from "./salter";
1
+ import libsodium from 'libsodium-wrappers-sumo';
8
2
 
3
+ import { Matter, MatterArgs, MtrDex } from './matter';
4
+ import { Signer } from './signer';
5
+ import { Cipher } from './cipher';
6
+ import { EmptyMaterialError } from './kering';
7
+ import { Salter } from './salter';
9
8
 
10
9
  export class Decrypter extends Matter {
11
10
  private readonly _decrypt: any;
12
- constructor({raw, code = MtrDex.X25519_Private, qb64, qb64b, qb2}:MatterArgs, seed: Uint8Array | undefined = undefined) {
11
+ constructor(
12
+ { raw, code = MtrDex.X25519_Private, qb64, qb64b, qb2 }: MatterArgs,
13
+ seed: Uint8Array | undefined = undefined
14
+ ) {
13
15
  try {
14
- super({raw, code, qb64, qb64b, qb2})
15
- } catch(e) {
16
- if(e instanceof EmptyMaterialError) {
16
+ super({ raw, code, qb64, qb64b, qb2 });
17
+ } catch (e) {
18
+ if (e instanceof EmptyMaterialError) {
17
19
  if (seed != undefined) {
18
- let signer = new Signer({qb64b: seed})
20
+ const signer = new Signer({ qb64b: seed });
19
21
  if (signer.code != MtrDex.Ed25519_Seed) {
20
- throw new Error(`Unsupported signing seed derivation code ${signer.code}`)
22
+ throw new Error(
23
+ `Unsupported signing seed derivation code ${signer.code}`
24
+ );
21
25
  }
22
- let sigkey = new Uint8Array(signer.raw.length + signer.verfer.raw.length)
23
- sigkey.set(signer.raw)
24
- sigkey.set(signer.verfer.raw, signer.raw.length)
25
- raw = libsodium.crypto_sign_ed25519_sk_to_curve25519(sigkey)
26
- super({raw, code, qb64, qb64b, qb2})
27
- }
28
- else {
29
- throw e
26
+ const sigkey = new Uint8Array(
27
+ signer.raw.length + signer.verfer.raw.length
28
+ );
29
+ sigkey.set(signer.raw);
30
+ sigkey.set(signer.verfer.raw, signer.raw.length);
31
+ raw =
32
+ libsodium.crypto_sign_ed25519_sk_to_curve25519(sigkey);
33
+ super({ raw, code, qb64, qb64b, qb2 });
34
+ } else {
35
+ throw e;
30
36
  }
31
37
  } else {
32
- throw e
38
+ throw e;
33
39
  }
34
40
  }
35
41
 
36
42
  if (this.code == MtrDex.X25519_Private) {
37
- this._decrypt = this._x25519
43
+ this._decrypt = this._x25519;
38
44
  } else {
39
- throw new Error(`Unsupported decrypter code = ${this.code}.`)
45
+ throw new Error(`Unsupported decrypter code = ${this.code}.`);
40
46
  }
41
47
  }
42
48
 
43
- decrypt(ser: Uint8Array | null = null, cipher: Cipher | null = null, transferable: boolean = false) {
49
+ decrypt(
50
+ ser: Uint8Array | null = null,
51
+ cipher: Cipher | null = null,
52
+ transferable: boolean = false
53
+ ) {
44
54
  if (ser == null && cipher == null) {
45
- throw new EmptyMaterialError("Neither ser or cipher were provided")
55
+ throw new EmptyMaterialError('Neither ser or cipher were provided');
46
56
  }
47
57
 
48
58
  if (ser != null) {
49
- cipher = new Cipher({qb64b: ser})
59
+ cipher = new Cipher({ qb64b: ser });
50
60
  }
51
61
 
52
- return this._decrypt(cipher, this.raw, transferable)
62
+ return this._decrypt(cipher, this.raw, transferable);
53
63
  }
54
64
 
55
65
  _x25519(cipher: Cipher, prikey: Uint8Array, transferable: boolean = false) {
56
- let pubkey = libsodium.crypto_scalarmult_base(prikey)
57
- let plain = libsodium.crypto_box_seal_open(cipher.raw, pubkey, prikey)
66
+ const pubkey = libsodium.crypto_scalarmult_base(prikey);
67
+ const plain = libsodium.crypto_box_seal_open(
68
+ cipher.raw,
69
+ pubkey,
70
+ prikey
71
+ );
58
72
  if (cipher.code == MtrDex.X25519_Cipher_Salt) {
59
- return new Salter({qb64b: plain})
73
+ return new Salter({ qb64b: plain });
60
74
  } else if (cipher.code == MtrDex.X25519_Cipher_Seed) {
61
- return new Signer({qb64b: plain, transferable: transferable})
75
+ return new Signer({ qb64b: plain, transferable: transferable });
62
76
  } else {
63
- throw new Error(`Unsupported cipher text code == ${cipher.code}`)
77
+ throw new Error(`Unsupported cipher text code == ${cipher.code}`);
64
78
  }
65
79
  }
66
- }
80
+ }
@@ -1,6 +1,6 @@
1
- import {createHash} from "blake3"
1
+ import { blake3 } from '@noble/hashes/blake3';
2
2
 
3
- import {Matter, MatterArgs, MtrDex} from './matter';
3
+ import { Matter, MatterArgs, MtrDex } from './matter';
4
4
 
5
5
  /**
6
6
  * @description : Diger is subset of Matter and is used to verify the digest of serialization
@@ -10,21 +10,25 @@ import {Matter, MatterArgs, MtrDex} from './matter';
10
10
  */
11
11
 
12
12
  export class Diger extends Matter {
13
- private readonly _verify: any
13
+ private readonly _verify: any;
14
14
 
15
15
  // This constructor will assign digest verification function to ._verify
16
- constructor({raw, code = MtrDex.Blake3_256, qb64, qb64b, qb2}: MatterArgs, ser: Uint8Array | null = null) {
16
+ constructor(
17
+ { raw, code = MtrDex.Blake3_256, qb64, qb64b, qb2 }: MatterArgs,
18
+ ser: Uint8Array | null = null
19
+ ) {
17
20
  try {
18
- super({raw, code, qb64, qb64b, qb2});
21
+ super({ raw, code, qb64, qb64b, qb2 });
19
22
  } catch (error) {
20
23
  if (ser == null) {
21
24
  throw error;
22
25
  }
23
26
 
24
27
  if (code === MtrDex.Blake3_256) {
25
- const hasher = createHash();
26
- const dig = hasher.update(ser).digest('');
27
- super({raw: dig, code: code});
28
+ const dig = Buffer.from(
29
+ blake3.create({ dkLen: 32 }).update(ser).digest()
30
+ );
31
+ super({ raw: dig, code: code });
28
32
  } else {
29
33
  throw new Error(`Unsupported code = ${code} for digester.`);
30
34
  }
@@ -37,7 +41,6 @@ export class Diger extends Matter {
37
41
  }
38
42
  }
39
43
 
40
-
41
44
  /**
42
45
  *
43
46
  * @param {Uint8Array} ser serialization bytes
@@ -49,34 +52,32 @@ export class Diger extends Matter {
49
52
  return this._verify(ser, this.raw);
50
53
  }
51
54
 
52
- compare(ser: Uint8Array, dig: any = null, diger: Diger | null = null ) {
55
+ compare(ser: Uint8Array, dig: any = null, diger: Diger | null = null) {
53
56
  if (dig != null) {
54
57
  if (dig.toString() == this.qb64) {
55
- return true
58
+ return true;
56
59
  }
57
60
 
58
- diger = new Diger({qb64b: dig})
61
+ diger = new Diger({ qb64b: dig });
59
62
  } else if (diger != null) {
60
63
  if (diger.qb64b == this.qb64b) {
61
64
  return true;
62
65
  }
63
- }
64
-
65
- else {
66
- throw new Error("Both dig and diger may not be None.")
66
+ } else {
67
+ throw new Error('Both dig and diger may not be None.');
67
68
  }
68
69
 
69
70
  if (diger.code == this.code) {
70
- return false
71
+ return false;
71
72
  }
72
73
 
73
- return diger.verify(ser) && this.verify(ser)
74
+ return diger.verify(ser) && this.verify(ser);
74
75
  }
75
76
 
76
-
77
77
  blake3_256(ser: Uint8Array, dig: any) {
78
- const hasher = createHash();
79
- let digest = hasher.update(ser).digest('');
80
- return (digest.toString() === dig.toString());
78
+ const digest = Buffer.from(
79
+ blake3.create({ dkLen: 32 }).update(ser).digest()
80
+ );
81
+ return digest.toString() === dig.toString();
81
82
  }
82
83
  }