signify-ts 0.1.0 → 0.2.0

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 (105) hide show
  1. package/README.md +101 -5
  2. package/dist/buffer-polyfill.d.ts +1 -0
  3. package/dist/exports.d.ts +40 -0
  4. package/dist/index.d.ts +4 -1
  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 +239 -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 -0
  15. package/dist/keri/app/notifying.d.ts +34 -0
  16. package/dist/keri/core/authing.d.ts +10 -0
  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 -68
  21. package/dist/keri/core/counter.d.ts +43 -0
  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 -0
  26. package/dist/keri/core/httping.d.ts +44 -0
  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 -151
  31. package/dist/keri/core/matter.d.ts +116 -47
  32. package/dist/keri/core/number.d.ts +7 -0
  33. package/dist/keri/core/pather.d.ts +7 -0
  34. package/dist/keri/core/prefixer.d.ts +15 -0
  35. package/dist/keri/core/saider.d.ts +23 -0
  36. package/dist/keri/core/salter.d.ts +23 -0
  37. package/dist/keri/core/seqner.d.ts +15 -0
  38. package/dist/keri/core/serder.d.ts +31 -0
  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 -0
  42. package/dist/keri/core/utils.d.ts +20 -14
  43. package/dist/keri/core/vdring.d.ts +16 -0
  44. package/dist/keri/core/verfer.d.ts +13 -0
  45. package/dist/keri/end/ending.d.ts +13 -0
  46. package/dist/math.d.ts +1 -0
  47. package/dist/ready.d.ts +1 -0
  48. package/dist/signify-ts.cjs +7835 -0
  49. package/dist/signify-ts.cjs.development.js +9493 -5
  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 +9341 -5
  55. package/dist/signify-ts.esm.js.map +1 -1
  56. package/dist/signify-ts.mjs +7811 -0
  57. package/dist/signify-ts.mjs.map +7 -0
  58. package/package.json +51 -49
  59. package/src/buffer-polyfill.ts +5 -0
  60. package/src/exports.ts +44 -0
  61. package/src/index.ts +4 -6
  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 +820 -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 +185 -0
  72. package/src/keri/app/notifying.ts +69 -0
  73. package/src/keri/core/authing.ts +117 -0
  74. package/src/keri/core/bexter.ts +138 -0
  75. package/src/keri/core/cigar.ts +11 -12
  76. package/src/keri/core/cipher.ts +23 -14
  77. package/src/keri/core/core.ts +249 -97
  78. package/src/keri/core/counter.ts +273 -0
  79. package/src/keri/core/decrypter.ts +48 -34
  80. package/src/keri/core/diger.ts +25 -24
  81. package/src/keri/core/encrypter.ts +37 -27
  82. package/src/keri/core/eventing.ts +581 -0
  83. package/src/keri/core/httping.ts +209 -0
  84. package/src/keri/core/indexer.ts +314 -211
  85. package/src/keri/core/keeping.ts +679 -4
  86. package/src/keri/core/kering.ts +4 -6
  87. package/src/keri/core/manager.ts +759 -450
  88. package/src/keri/core/matter.ts +404 -135
  89. package/src/keri/core/number.ts +66 -0
  90. package/src/keri/core/pather.ts +98 -0
  91. package/src/keri/core/prefixer.ts +233 -0
  92. package/src/keri/core/saider.ts +186 -0
  93. package/src/keri/core/salter.ts +76 -41
  94. package/src/keri/core/seqner.ts +46 -0
  95. package/src/keri/core/serder.ts +163 -0
  96. package/src/keri/core/siger.ts +19 -18
  97. package/src/keri/core/signer.ts +74 -53
  98. package/src/keri/core/tholder.ts +218 -0
  99. package/src/keri/core/utils.ts +120 -45
  100. package/src/keri/core/vdring.ts +94 -0
  101. package/src/keri/core/verfer.ts +25 -11
  102. package/src/keri/end/ending.ts +170 -0
  103. package/src/math.ts +3 -0
  104. package/src/ready.ts +5 -0
  105. package/src/keri/core/tsconfig.json +0 -100
@@ -0,0 +1,273 @@
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(
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 = '';
113
+ private _count: number = -1;
114
+
115
+ constructor({ code, count, countB64, qb64b, qb64, qb2 }: CounterArgs) {
116
+ if (code != undefined) {
117
+ if (!Counter.Sizes.has(code)) {
118
+ throw new Error(`"Unsupported code=${code}.`);
119
+ }
120
+
121
+ const sizage = Counter.Sizes.get(code)!;
122
+ const cs = sizage.hs + sizage.ss;
123
+ if (sizage.fs != cs || cs % 4 != 0) {
124
+ throw new Error(
125
+ `Whole code size not full size or not multiple of 4. cs=${cs} fs=${sizage.fs}.`
126
+ );
127
+ }
128
+
129
+ if (count == undefined) {
130
+ count = countB64 == undefined ? 1 : b64ToInt(countB64);
131
+ }
132
+
133
+ if (count < 0 || count > 64 ** sizage.ss - 1) {
134
+ throw new Error(`Invalid count=${count} for code=${code}.`);
135
+ }
136
+
137
+ this._code = code;
138
+ this._count = count;
139
+ } else if (qb64b != undefined) {
140
+ const qb64 = d(qb64b);
141
+ this._exfil(qb64);
142
+ } else if (qb64 != undefined) {
143
+ this._exfil(qb64);
144
+ } else if (qb2 != undefined) {
145
+ } else {
146
+ throw new Error(
147
+ `Improper initialization need either (code and count) or qb64b or qb64 or qb2.`
148
+ );
149
+ }
150
+ }
151
+
152
+ get code(): string {
153
+ return this._code;
154
+ }
155
+
156
+ get count() {
157
+ return this._count;
158
+ }
159
+
160
+ get qb64() {
161
+ return this._infil();
162
+ }
163
+
164
+ get qb64b() {
165
+ return b(this.qb64);
166
+ }
167
+
168
+ countToB64(l?: number): string {
169
+ if (l == undefined) {
170
+ const sizage = Counter.Sizes.get(this.code)!;
171
+ l = sizage.ss;
172
+ }
173
+ return intToB64(this.count, l);
174
+ }
175
+
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;
192
+ for (let i = 0; i < x; i++) {
193
+ splits.push(parts[i + off]);
194
+ }
195
+ parts = splits;
196
+ }
197
+
198
+ parts.forEach((p) => {
199
+ if (p < 0 || p > 63) {
200
+ throw new Error(
201
+ `Out of bounds semantic version. Part=${p} is < 0 or > 63.`
202
+ );
203
+ }
204
+ });
205
+
206
+ return parts
207
+ .map((p) => {
208
+ return intToB64(p, 1);
209
+ })
210
+ .join('');
211
+ }
212
+
213
+ private _infil(): string {
214
+ const code = this.code;
215
+ const count = this.count;
216
+
217
+ const sizage = Counter.Sizes.get(code)!;
218
+ const cs = sizage.hs + sizage.ss;
219
+ if (sizage.fs != cs || cs % 4 != 0) {
220
+ throw new Error(
221
+ `Whole code size not full size or not multiple of 4. cs=${cs} fs=${sizage.fs}.`
222
+ );
223
+ }
224
+
225
+ if (count < 0 || count > 64 ** sizage.ss - 1) {
226
+ throw new Error(`Invalid count=${count} for code=${code}.`);
227
+ }
228
+
229
+ const both = `${code}${intToB64(count, sizage.ss)}`;
230
+
231
+ if (both.length % 4) {
232
+ throw new Error(
233
+ `Invalid size = ${both.length} of ${both} not a multiple of 4.`
234
+ );
235
+ }
236
+
237
+ return both;
238
+ }
239
+
240
+ private _exfil(qb64: string) {
241
+ if (qb64.length == 0) {
242
+ throw new Error('Empty Material');
243
+ }
244
+
245
+ const first = qb64.slice(0, 2);
246
+ if (!Counter.Hards.has(first)) {
247
+ throw new Error(`Unexpected code ${first}`);
248
+ }
249
+
250
+ const hs = Counter.Hards.get(first)!;
251
+ if (qb64.length < hs) {
252
+ throw new Error(`Need ${hs - qb64.length} more characters.`);
253
+ }
254
+
255
+ const hard = qb64.slice(0, hs);
256
+ if (!Counter.Sizes.has(hard)) {
257
+ throw new Error(`Unsupported code ${hard}`);
258
+ }
259
+
260
+ const sizage = Counter.Sizes.get(hard)!;
261
+ const cs = sizage!.hs + sizage!.ss;
262
+
263
+ if (qb64.length < cs) {
264
+ throw new Error(`Need ${cs - qb64.length} more chars.`);
265
+ }
266
+
267
+ const scount = qb64.slice(sizage.hs, sizage.hs + sizage.ss);
268
+ const count = b64ToInt(scount);
269
+
270
+ this._code = hard;
271
+ this._count = count;
272
+ }
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,5 +1,6 @@
1
- const blake3 = require('blake3');
2
- import {Matter, MatterArgs, MtrDex} from './matter';
1
+ import { blake3 } from '@noble/hashes/blake3';
2
+
3
+ import { Matter, MatterArgs, MtrDex } from './matter';
3
4
 
4
5
  /**
5
6
  * @description : Diger is subset of Matter and is used to verify the digest of serialization
@@ -8,23 +9,26 @@ import {Matter, MatterArgs, MtrDex} from './matter';
8
9
  *
9
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});
19
- } catch (error: any) {
21
+ super({ raw, code, qb64, qb64b, qb2 });
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 = blake3.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 = blake3.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
  }
@@ -1,60 +1,70 @@
1
- import libsodium from "libsodium-wrappers-sumo";
2
-
3
- import {Matter, MatterArgs, MtrDex} from './matter';
4
- import {Verfer} from "./verfer";
5
- import {Signer} from "./signer";
6
- import {Cipher} from "./cipher";
7
- import {arrayEquals} from "./utils";
1
+ import libsodium from 'libsodium-wrappers-sumo';
8
2
 
3
+ import { Matter, MatterArgs, MtrDex } from './matter';
4
+ import { Verfer } from './verfer';
5
+ import { Signer } from './signer';
6
+ import { Cipher } from './cipher';
7
+ import { arrayEquals } from './utils';
9
8
 
10
9
  export class Encrypter extends Matter {
11
10
  private _encrypt: any;
12
- constructor({raw, code = MtrDex.X25519, qb64, qb64b, qb2}:MatterArgs, verkey: Uint8Array | null = null) {
11
+ constructor(
12
+ { raw, code = MtrDex.X25519, qb64, qb64b, qb2 }: MatterArgs,
13
+ verkey: Uint8Array | null = null
14
+ ) {
13
15
  if (raw == undefined && verkey != null) {
14
- let verfer = new Verfer({qb64b: verkey})
15
- if (!Array.from([MtrDex.Ed25519N, MtrDex.Ed25519]).includes(verfer.code)) {
16
- throw new Error(`Unsupported verkey derivation code = ${verfer.code}.`)
16
+ const verfer = new Verfer({ qb64b: verkey });
17
+ if (
18
+ !Array.from([MtrDex.Ed25519N, MtrDex.Ed25519]).includes(
19
+ verfer.code
20
+ )
21
+ ) {
22
+ throw new Error(
23
+ `Unsupported verkey derivation code = ${verfer.code}.`
24
+ );
17
25
  }
18
- raw = libsodium.crypto_sign_ed25519_pk_to_curve25519(verfer.raw)
26
+ raw = libsodium.crypto_sign_ed25519_pk_to_curve25519(verfer.raw);
19
27
  }
20
28
 
21
- super({raw, code, qb64, qb64b, qb2});
29
+ super({ raw, code, qb64, qb64b, qb2 });
22
30
 
23
31
  if (this.code == MtrDex.X25519) {
24
32
  this._encrypt = this._x25519;
25
33
  } else {
26
- throw new Error(`Unsupported encrypter code = ${this.code}.`)
34
+ throw new Error(`Unsupported encrypter code = ${this.code}.`);
27
35
  }
28
36
  }
29
37
 
30
38
  verifySeed(seed: Uint8Array) {
31
- let signer = new Signer({qb64b: seed})
32
- let keypair = libsodium.crypto_sign_seed_keypair(signer.raw);
33
- let pubkey = libsodium.crypto_sign_ed25519_pk_to_curve25519(keypair.publicKey)
34
- return arrayEquals(pubkey, this.raw)
39
+ const signer = new Signer({ qb64b: seed });
40
+ const keypair = libsodium.crypto_sign_seed_keypair(signer.raw);
41
+ const pubkey = libsodium.crypto_sign_ed25519_pk_to_curve25519(
42
+ keypair.publicKey
43
+ );
44
+ return arrayEquals(pubkey, this.raw);
35
45
  }
36
46
 
37
47
  encrypt(ser: Uint8Array | null = null, matter: Matter | null = null) {
38
48
  if (ser == null && matter == null) {
39
- throw new Error("Neither ser nor matter are provided.")
49
+ throw new Error('Neither ser nor matter are provided.');
40
50
  }
41
51
 
42
52
  if (ser != null) {
43
- matter = new Matter({qb64b: ser})
53
+ matter = new Matter({ qb64b: ser });
44
54
  }
45
55
 
46
- let code
56
+ let code;
47
57
  if (matter!.code == MtrDex.Salt_128) {
48
- code = MtrDex.X25519_Cipher_Salt
58
+ code = MtrDex.X25519_Cipher_Salt;
49
59
  } else {
50
- code = MtrDex.X25519_Cipher_Seed
60
+ code = MtrDex.X25519_Cipher_Seed;
51
61
  }
52
62
 
53
- return this._encrypt(matter!.qb64, this.raw, code)
63
+ return this._encrypt(matter!.qb64, this.raw, code);
54
64
  }
55
65
 
56
66
  _x25519(ser: Uint8Array, pubkey: Uint8Array, code: string) {
57
- let raw = libsodium.crypto_box_seal(ser, pubkey)
58
- return new Cipher({raw: raw, code: code})
67
+ const raw = libsodium.crypto_box_seal(ser, pubkey);
68
+ return new Cipher({ raw: raw, code: code });
59
69
  }
60
- }
70
+ }