signify-ts 0.2.0 → 0.3.0-dev.e31e78d

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 (129) hide show
  1. package/README.md +104 -34
  2. package/dist/exports.d.ts +40 -40
  3. package/dist/exports.js +40 -0
  4. package/dist/index.d.ts +2 -3
  5. package/dist/index.js +3 -8
  6. package/dist/keri/app/aiding.d.ts +54 -18
  7. package/{src/keri/app/aiding.ts → dist/keri/app/aiding.js} +130 -236
  8. package/dist/keri/app/clienting.d.ts +59 -22
  9. package/{src/keri/app/clienting.ts → dist/keri/app/clienting.js} +146 -235
  10. package/dist/keri/app/contacting.d.ts +30 -23
  11. package/{src/keri/app/contacting.ts → dist/keri/app/contacting.js} +26 -63
  12. package/dist/keri/app/controller.d.ts +49 -6
  13. package/{src/keri/app/controller.ts → dist/keri/app/controller.js} +80 -186
  14. package/dist/keri/app/coring.d.ts +134 -25
  15. package/{src/keri/app/coring.ts → dist/keri/app/coring.js} +83 -56
  16. package/dist/keri/app/credentialing.d.ts +191 -67
  17. package/dist/keri/app/credentialing.js +540 -0
  18. package/dist/keri/app/delegating.d.ts +18 -0
  19. package/dist/keri/app/delegating.js +24 -0
  20. package/dist/keri/app/escrowing.d.ts +5 -3
  21. package/{src/keri/app/escrowing.ts → dist/keri/app/escrowing.js} +3 -9
  22. package/dist/keri/app/exchanging.d.ts +243 -11
  23. package/dist/keri/app/exchanging.js +242 -0
  24. package/dist/keri/app/grouping.d.ts +11 -9
  25. package/{src/keri/app/grouping.ts → dist/keri/app/grouping.js} +10 -29
  26. package/dist/keri/app/habery.d.ts +2 -2
  27. package/dist/keri/app/habery.js +117 -0
  28. package/dist/keri/app/notifying.d.ts +2 -2
  29. package/{src/keri/app/notifying.ts → dist/keri/app/notifying.js} +7 -17
  30. package/dist/keri/core/authing.d.ts +2 -2
  31. package/{src/keri/core/authing.ts → dist/keri/core/authing.js} +26 -42
  32. package/dist/keri/core/base64.d.ts +2 -0
  33. package/dist/keri/core/base64.js +16 -0
  34. package/dist/keri/core/bexter.d.ts +1 -1
  35. package/{src/keri/core/bexter.ts → dist/keri/core/bexter.js} +18 -32
  36. package/dist/keri/core/cigar.d.ts +2 -2
  37. package/dist/keri/core/cigar.js +13 -0
  38. package/dist/keri/core/cipher.d.ts +1 -1
  39. package/{src/keri/core/cipher.ts → dist/keri/core/cipher.js} +10 -19
  40. package/dist/keri/core/core.d.ts +117 -9
  41. package/dist/keri/core/core.js +385 -0
  42. package/dist/keri/core/counter.d.ts +2 -2
  43. package/dist/keri/core/counter.js +221 -0
  44. package/dist/keri/core/decrypter.d.ts +4 -4
  45. package/{src/keri/core/decrypter.ts → dist/keri/core/decrypter.js} +23 -40
  46. package/dist/keri/core/diger.d.ts +3 -3
  47. package/{src/keri/core/diger.ts → dist/keri/core/diger.js} +18 -33
  48. package/dist/keri/core/encrypter.d.ts +2 -2
  49. package/{src/keri/core/encrypter.ts → dist/keri/core/encrypter.js} +18 -38
  50. package/dist/keri/core/eventing.d.ts +6 -6
  51. package/dist/keri/core/eventing.js +383 -0
  52. package/dist/keri/core/httping.d.ts +11 -4
  53. package/{src/keri/core/httping.ts → dist/keri/core/httping.js} +36 -101
  54. package/dist/keri/core/indexer.d.ts +1 -1
  55. package/dist/keri/core/indexer.js +407 -0
  56. package/dist/keri/core/keeping.d.ts +113 -46
  57. package/dist/keri/core/keeping.js +347 -0
  58. package/{src/keri/core/kering.ts → dist/keri/core/kering.js} +1 -3
  59. package/dist/keri/core/keyState.d.ts +98 -0
  60. package/dist/keri/core/manager.d.ts +147 -12
  61. package/dist/keri/core/manager.js +880 -0
  62. package/dist/keri/core/matter.d.ts +1 -1
  63. package/dist/keri/core/matter.js +460 -0
  64. package/dist/keri/core/number.d.ts +2 -2
  65. package/{src/keri/core/number.ts → dist/keri/core/number.js} +26 -32
  66. package/dist/keri/core/pather.d.ts +2 -2
  67. package/{src/keri/core/pather.ts → dist/keri/core/pather.js} +12 -27
  68. package/dist/keri/core/prefixer.d.ts +10 -10
  69. package/dist/keri/core/prefixer.js +182 -0
  70. package/dist/keri/core/saider.d.ts +2 -12
  71. package/dist/keri/core/saider.js +107 -0
  72. package/dist/keri/core/salter.d.ts +44 -9
  73. package/dist/keri/core/salter.js +110 -0
  74. package/dist/keri/core/seqner.d.ts +1 -1
  75. package/{src/keri/core/seqner.ts → dist/keri/core/seqner.js} +20 -21
  76. package/dist/keri/core/serder.d.ts +25 -12
  77. package/dist/keri/core/serder.js +133 -0
  78. package/dist/keri/core/siger.d.ts +2 -2
  79. package/{src/keri/core/siger.ts → dist/keri/core/siger.js} +4 -14
  80. package/dist/keri/core/signer.d.ts +4 -4
  81. package/dist/keri/core/signer.js +84 -0
  82. package/{src/keri/core/tholder.ts → dist/keri/core/tholder.js} +69 -94
  83. package/dist/keri/core/utils.d.ts +1 -1
  84. package/{src/keri/core/utils.ts → dist/keri/core/utils.js} +30 -60
  85. package/dist/keri/core/vdring.d.ts +2 -2
  86. package/dist/keri/core/vdring.js +61 -0
  87. package/dist/keri/core/verfer.d.ts +2 -6
  88. package/dist/keri/core/verfer.js +37 -0
  89. package/dist/keri/end/ending.d.ts +10 -8
  90. package/dist/keri/end/ending.js +136 -0
  91. package/{src/ready.ts → dist/ready.js} +1 -2
  92. package/dist/types/keria-api-schema.d.ts +1158 -0
  93. package/dist/types/keria-api-schema.js +34 -0
  94. package/package.json +53 -52
  95. package/dist/math.d.ts +0 -1
  96. package/dist/signify-ts.cjs +0 -7835
  97. package/dist/signify-ts.cjs.development.js +0 -9501
  98. package/dist/signify-ts.cjs.development.js.map +0 -1
  99. package/dist/signify-ts.cjs.map +0 -7
  100. package/dist/signify-ts.cjs.production.min.js +0 -2
  101. package/dist/signify-ts.cjs.production.min.js.map +0 -1
  102. package/dist/signify-ts.esm.js +0 -9345
  103. package/dist/signify-ts.esm.js.map +0 -1
  104. package/dist/signify-ts.mjs +0 -7811
  105. package/dist/signify-ts.mjs.map +0 -7
  106. package/src/buffer-polyfill.ts +0 -5
  107. package/src/exports.ts +0 -44
  108. package/src/index.ts +0 -4
  109. package/src/keri/app/credentialing.ts +0 -820
  110. package/src/keri/app/exchanging.ts +0 -220
  111. package/src/keri/app/habery.ts +0 -185
  112. package/src/keri/core/cigar.ts +0 -18
  113. package/src/keri/core/core.ts +0 -326
  114. package/src/keri/core/counter.ts +0 -273
  115. package/src/keri/core/eventing.ts +0 -581
  116. package/src/keri/core/indexer.ts +0 -509
  117. package/src/keri/core/keeping.ts +0 -684
  118. package/src/keri/core/manager.ts +0 -1183
  119. package/src/keri/core/matter.ts +0 -521
  120. package/src/keri/core/prefixer.ts +0 -233
  121. package/src/keri/core/saider.ts +0 -186
  122. package/src/keri/core/salter.ts +0 -120
  123. package/src/keri/core/serder.ts +0 -163
  124. package/src/keri/core/signer.ts +0 -133
  125. package/src/keri/core/vdring.ts +0 -94
  126. package/src/keri/core/verfer.ts +0 -47
  127. package/src/keri/end/ending.ts +0 -170
  128. package/src/math.ts +0 -3
  129. /package/dist/{buffer-polyfill.d.ts → keri/core/keyState.js} +0 -0
@@ -0,0 +1,221 @@
1
+ import { Codex, Sizage } from "./matter.js";
2
+ import { b, b64ToInt, d, intToB64 } from "./core.js";
3
+ export class CounterCodex extends Codex {
4
+ constructor() {
5
+ super(...arguments);
6
+ this.ControllerIdxSigs = '-A'; // Qualified Base64 Indexed Signature.
7
+ this.WitnessIdxSigs = '-B'; // Qualified Base64 Indexed Signature.
8
+ this.NonTransReceiptCouples = '-C'; // Composed Base64 Couple, pre+cig.
9
+ this.TransReceiptQuadruples = '-D'; // Composed Base64 Quadruple, pre+snu+dig+sig.
10
+ this.FirstSeenReplayCouples = '-E'; // Composed Base64 Couple, fnu+dts.
11
+ this.TransIdxSigGroups = '-F'; // Composed Base64 Group, pre+snu+dig+ControllerIdxSigs group.
12
+ this.SealSourceCouples = '-G'; // Composed Base64 couple, snu+dig of given delegators or issuers event
13
+ this.TransLastIdxSigGroups = '-H'; // Composed Base64 Group, pre+ControllerIdxSigs group.
14
+ this.SealSourceTriples = '-I'; // Composed Base64 triple, pre+snu+dig of anchoring source event
15
+ this.SadPathSig = '-J'; // Composed Base64 Group path+TransIdxSigGroup of SAID of content
16
+ this.SadPathSigGroup = '-K'; // Composed Base64 Group, root(path)+SaidPathCouples
17
+ this.PathedMaterialQuadlets = '-L'; // Composed Grouped Pathed Material Quadlet (4 char each)
18
+ this.AttachedMaterialQuadlets = '-V'; // Composed Grouped Attached Material Quadlet (4 char each)
19
+ this.BigAttachedMaterialQuadlets = '-0V'; // Composed Grouped Attached Material Quadlet (4 char each)
20
+ this.KERIProtocolStack = '--AAA'; // KERI ACDC Protocol Stack CESR Version
21
+ }
22
+ }
23
+ export const CtrDex = new CounterCodex();
24
+ export class Counter {
25
+ constructor({ code, count, countB64, qb64b, qb64, qb2 }) {
26
+ this._code = '';
27
+ this._count = -1;
28
+ if (code != undefined) {
29
+ if (!Counter.Sizes.has(code)) {
30
+ throw new Error(`"Unsupported code=${code}.`);
31
+ }
32
+ const sizage = Counter.Sizes.get(code);
33
+ const cs = sizage.hs + sizage.ss;
34
+ if (sizage.fs != cs || cs % 4 != 0) {
35
+ throw new Error(`Whole code size not full size or not multiple of 4. cs=${cs} fs=${sizage.fs}.`);
36
+ }
37
+ if (count == undefined) {
38
+ count = countB64 == undefined ? 1 : b64ToInt(countB64);
39
+ }
40
+ if (count < 0 || count > 64 ** sizage.ss - 1) {
41
+ throw new Error(`Invalid count=${count} for code=${code}.`);
42
+ }
43
+ this._code = code;
44
+ this._count = count;
45
+ }
46
+ else if (qb64b != undefined) {
47
+ const qb64 = d(qb64b);
48
+ this._exfil(qb64);
49
+ }
50
+ else if (qb64 != undefined) {
51
+ this._exfil(qb64);
52
+ }
53
+ else if (qb2 != undefined) {
54
+ }
55
+ else {
56
+ throw new Error(`Improper initialization need either (code and count) or qb64b or qb64 or qb2.`);
57
+ }
58
+ }
59
+ get code() {
60
+ return this._code;
61
+ }
62
+ get count() {
63
+ return this._count;
64
+ }
65
+ get qb64() {
66
+ return this._infil();
67
+ }
68
+ get qb64b() {
69
+ return b(this.qb64);
70
+ }
71
+ countToB64(l) {
72
+ if (l == undefined) {
73
+ const sizage = Counter.Sizes.get(this.code);
74
+ l = sizage.ss;
75
+ }
76
+ return intToB64(this.count, l);
77
+ }
78
+ static semVerToB64(version = '', major = 0, minor = 0, patch = 0) {
79
+ let parts = [major, minor, patch];
80
+ if (version != '') {
81
+ const ssplits = version.split('.');
82
+ const splits = ssplits.map((x) => {
83
+ if (x == '')
84
+ return 0;
85
+ return parseInt(x);
86
+ });
87
+ const off = splits.length;
88
+ const x = 3 - off;
89
+ for (let i = 0; i < x; i++) {
90
+ splits.push(parts[i + off]);
91
+ }
92
+ parts = splits;
93
+ }
94
+ parts.forEach((p) => {
95
+ if (p < 0 || p > 63) {
96
+ throw new Error(`Out of bounds semantic version. Part=${p} is < 0 or > 63.`);
97
+ }
98
+ });
99
+ return parts
100
+ .map((p) => {
101
+ return intToB64(p, 1);
102
+ })
103
+ .join('');
104
+ }
105
+ _infil() {
106
+ const code = this.code;
107
+ const count = this.count;
108
+ const sizage = Counter.Sizes.get(code);
109
+ const cs = sizage.hs + sizage.ss;
110
+ if (sizage.fs != cs || cs % 4 != 0) {
111
+ throw new Error(`Whole code size not full size or not multiple of 4. cs=${cs} fs=${sizage.fs}.`);
112
+ }
113
+ if (count < 0 || count > 64 ** sizage.ss - 1) {
114
+ throw new Error(`Invalid count=${count} for code=${code}.`);
115
+ }
116
+ const both = `${code}${intToB64(count, sizage.ss)}`;
117
+ if (both.length % 4) {
118
+ throw new Error(`Invalid size = ${both.length} of ${both} not a multiple of 4.`);
119
+ }
120
+ return both;
121
+ }
122
+ _exfil(qb64) {
123
+ if (qb64.length == 0) {
124
+ throw new Error('Empty Material');
125
+ }
126
+ const first = qb64.slice(0, 2);
127
+ if (!Counter.Hards.has(first)) {
128
+ throw new Error(`Unexpected code ${first}`);
129
+ }
130
+ const hs = Counter.Hards.get(first);
131
+ if (qb64.length < hs) {
132
+ throw new Error(`Need ${hs - qb64.length} more characters.`);
133
+ }
134
+ const hard = qb64.slice(0, hs);
135
+ if (!Counter.Sizes.has(hard)) {
136
+ throw new Error(`Unsupported code ${hard}`);
137
+ }
138
+ const sizage = Counter.Sizes.get(hard);
139
+ const cs = sizage.hs + sizage.ss;
140
+ if (qb64.length < cs) {
141
+ throw new Error(`Need ${cs - qb64.length} more chars.`);
142
+ }
143
+ const scount = qb64.slice(sizage.hs, sizage.hs + sizage.ss);
144
+ const count = b64ToInt(scount);
145
+ this._code = hard;
146
+ this._count = count;
147
+ }
148
+ }
149
+ Counter.Sizes = new Map(Object.entries({
150
+ '-A': new Sizage(2, 2, 4, 0),
151
+ '-B': new Sizage(2, 2, 4, 0),
152
+ '-C': new Sizage(2, 2, 4, 0),
153
+ '-D': new Sizage(2, 2, 4, 0),
154
+ '-E': new Sizage(2, 2, 4, 0),
155
+ '-F': new Sizage(2, 2, 4, 0),
156
+ '-G': new Sizage(2, 2, 4, 0),
157
+ '-H': new Sizage(2, 2, 4, 0),
158
+ '-I': new Sizage(2, 2, 4, 0),
159
+ '-J': new Sizage(2, 2, 4, 0),
160
+ '-K': new Sizage(2, 2, 4, 0),
161
+ '-L': new Sizage(2, 2, 4, 0),
162
+ '-V': new Sizage(2, 2, 4, 0),
163
+ '-0V': new Sizage(3, 5, 8, 0),
164
+ '--AAA': new Sizage(5, 3, 8, 0),
165
+ }));
166
+ Counter.Hards = new Map([
167
+ ['-A', 2],
168
+ ['-B', 2],
169
+ ['-C', 2],
170
+ ['-D', 2],
171
+ ['-E', 2],
172
+ ['-F', 2],
173
+ ['-G', 2],
174
+ ['-H', 2],
175
+ ['-I', 2],
176
+ ['-J', 2],
177
+ ['-K', 2],
178
+ ['-L', 2],
179
+ ['-M', 2],
180
+ ['-N', 2],
181
+ ['-O', 2],
182
+ ['-P', 2],
183
+ ['-Q', 2],
184
+ ['-R', 2],
185
+ ['-S', 2],
186
+ ['-T', 2],
187
+ ['-U', 2],
188
+ ['-V', 2],
189
+ ['-W', 2],
190
+ ['-X', 2],
191
+ ['-Y', 2],
192
+ ['-Z', 2],
193
+ ['-a', 2],
194
+ ['-b', 2],
195
+ ['-c', 2],
196
+ ['-d', 2],
197
+ ['-e', 2],
198
+ ['-f', 2],
199
+ ['-g', 2],
200
+ ['-h', 2],
201
+ ['-i', 2],
202
+ ['-j', 2],
203
+ ['-k', 2],
204
+ ['-l', 2],
205
+ ['-m', 2],
206
+ ['-n', 2],
207
+ ['-o', 2],
208
+ ['-p', 2],
209
+ ['-q', 2],
210
+ ['-r', 2],
211
+ ['-s', 2],
212
+ ['-t', 2],
213
+ ['-u', 2],
214
+ ['-v', 2],
215
+ ['-w', 2],
216
+ ['-x', 2],
217
+ ['-y', 2],
218
+ ['-z', 2],
219
+ ['-0', 3],
220
+ ['--', 5],
221
+ ]);
@@ -1,7 +1,7 @@
1
- import { Matter, MatterArgs } from './matter';
2
- import { Signer } from './signer';
3
- import { Cipher } from './cipher';
4
- import { Salter } from './salter';
1
+ import { Matter, MatterArgs } from './matter.ts';
2
+ import { Signer } from './signer.ts';
3
+ import { Cipher } from './cipher.ts';
4
+ import { Salter } from './salter.ts';
5
5
  export declare class Decrypter extends Matter {
6
6
  private readonly _decrypt;
7
7
  constructor({ raw, code, qb64, qb64b, qb2 }: MatterArgs, seed?: Uint8Array | undefined);
@@ -1,79 +1,62 @@
1
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';
8
-
2
+ import { Matter, MtrDex } from "./matter.js";
3
+ import { Signer } from "./signer.js";
4
+ import { Cipher } from "./cipher.js";
5
+ import { EmptyMaterialError } from "./kering.js";
6
+ import { Salter } from "./salter.js";
9
7
  export class Decrypter extends Matter {
10
- private readonly _decrypt: any;
11
- constructor(
12
- { raw, code = MtrDex.X25519_Private, qb64, qb64b, qb2 }: MatterArgs,
13
- seed: Uint8Array | undefined = undefined
14
- ) {
8
+ constructor({ raw, code = MtrDex.X25519_Private, qb64, qb64b, qb2 }, seed = undefined) {
15
9
  try {
16
10
  super({ raw, code, qb64, qb64b, qb2 });
17
- } catch (e) {
11
+ }
12
+ catch (e) {
18
13
  if (e instanceof EmptyMaterialError) {
19
14
  if (seed != undefined) {
20
15
  const signer = new Signer({ qb64b: seed });
21
16
  if (signer.code != MtrDex.Ed25519_Seed) {
22
- throw new Error(
23
- `Unsupported signing seed derivation code ${signer.code}`
24
- );
17
+ throw new Error(`Unsupported signing seed derivation code ${signer.code}`);
25
18
  }
26
- const sigkey = new Uint8Array(
27
- signer.raw.length + signer.verfer.raw.length
28
- );
19
+ const sigkey = new Uint8Array(signer.raw.length + signer.verfer.raw.length);
29
20
  sigkey.set(signer.raw);
30
21
  sigkey.set(signer.verfer.raw, signer.raw.length);
31
22
  raw =
32
23
  libsodium.crypto_sign_ed25519_sk_to_curve25519(sigkey);
33
24
  super({ raw, code, qb64, qb64b, qb2 });
34
- } else {
25
+ }
26
+ else {
35
27
  throw e;
36
28
  }
37
- } else {
29
+ }
30
+ else {
38
31
  throw e;
39
32
  }
40
33
  }
41
-
42
34
  if (this.code == MtrDex.X25519_Private) {
43
35
  this._decrypt = this._x25519;
44
- } else {
36
+ }
37
+ else {
45
38
  throw new Error(`Unsupported decrypter code = ${this.code}.`);
46
39
  }
47
40
  }
48
-
49
- decrypt(
50
- ser: Uint8Array | null = null,
51
- cipher: Cipher | null = null,
52
- transferable: boolean = false
53
- ) {
41
+ decrypt(ser = null, cipher = null, transferable = false) {
54
42
  if (ser == null && cipher == null) {
55
43
  throw new EmptyMaterialError('Neither ser or cipher were provided');
56
44
  }
57
-
58
45
  if (ser != null) {
59
46
  cipher = new Cipher({ qb64b: ser });
60
47
  }
61
-
62
48
  return this._decrypt(cipher, this.raw, transferable);
63
49
  }
64
-
65
- _x25519(cipher: Cipher, prikey: Uint8Array, transferable: boolean = false) {
50
+ _x25519(cipher, prikey, transferable = false) {
66
51
  const pubkey = libsodium.crypto_scalarmult_base(prikey);
67
- const plain = libsodium.crypto_box_seal_open(
68
- cipher.raw,
69
- pubkey,
70
- prikey
71
- );
52
+ const plain = libsodium.crypto_box_seal_open(cipher.raw, pubkey, prikey);
72
53
  if (cipher.code == MtrDex.X25519_Cipher_Salt) {
73
54
  return new Salter({ qb64b: plain });
74
- } else if (cipher.code == MtrDex.X25519_Cipher_Seed) {
55
+ }
56
+ else if (cipher.code == MtrDex.X25519_Cipher_Seed) {
75
57
  return new Signer({ qb64b: plain, transferable: transferable });
76
- } else {
58
+ }
59
+ else {
77
60
  throw new Error(`Unsupported cipher text code == ${cipher.code}`);
78
61
  }
79
62
  }
@@ -1,4 +1,4 @@
1
- import { Matter, MatterArgs } from './matter';
1
+ import { Matter, MatterArgs } from './matter.ts';
2
2
  /**
3
3
  * @description : Diger is subset of Matter and is used to verify the digest of serialization
4
4
  * It uses .raw : as digest
@@ -16,6 +16,6 @@ export declare class Diger extends Matter {
16
16
  by .code
17
17
  */
18
18
  verify(ser: Uint8Array): boolean;
19
- compare(ser: Uint8Array, dig?: any, diger?: Diger | null): boolean;
20
- blake3_256(ser: Uint8Array, dig: any): boolean;
19
+ compare(ser: Uint8Array, dig?: Uint8Array | null, diger?: Diger | null): boolean;
20
+ blake3_256(ser: Uint8Array, dig: Uint8Array): boolean;
21
21
  }
@@ -1,46 +1,36 @@
1
1
  import { blake3 } from '@noble/hashes/blake3';
2
-
3
- import { Matter, MatterArgs, MtrDex } from './matter';
4
-
2
+ import { Matter, MtrDex } from "./matter.js";
5
3
  /**
6
4
  * @description : Diger is subset of Matter and is used to verify the digest of serialization
7
5
  * It uses .raw : as digest
8
6
  * .code as digest algorithm
9
7
  *
10
8
  */
11
-
12
9
  export class Diger extends Matter {
13
- private readonly _verify: any;
14
-
15
10
  // This constructor will assign digest verification function to ._verify
16
- constructor(
17
- { raw, code = MtrDex.Blake3_256, qb64, qb64b, qb2 }: MatterArgs,
18
- ser: Uint8Array | null = null
19
- ) {
11
+ constructor({ raw, code = MtrDex.Blake3_256, qb64, qb64b, qb2 }, ser = null) {
20
12
  try {
21
13
  super({ raw, code, qb64, qb64b, qb2 });
22
- } catch (error) {
14
+ }
15
+ catch (error) {
23
16
  if (ser == null) {
24
17
  throw error;
25
18
  }
26
-
27
19
  if (code === MtrDex.Blake3_256) {
28
- const dig = Buffer.from(
29
- blake3.create({ dkLen: 32 }).update(ser).digest()
30
- );
20
+ const dig = blake3.create({ dkLen: 32 }).update(ser).digest();
31
21
  super({ raw: dig, code: code });
32
- } else {
22
+ }
23
+ else {
33
24
  throw new Error(`Unsupported code = ${code} for digester.`);
34
25
  }
35
26
  }
36
-
37
27
  if (code === MtrDex.Blake3_256) {
38
28
  this._verify = this.blake3_256;
39
- } else {
29
+ }
30
+ else {
40
31
  throw new Error(`Unsupported code = ${code} for digester.`);
41
32
  }
42
33
  }
43
-
44
34
  /**
45
35
  *
46
36
  * @param {Uint8Array} ser serialization bytes
@@ -48,36 +38,31 @@ export class Diger extends Matter {
48
38
  * using .raw as reference digest for ._verify digest algorithm determined
49
39
  by .code
50
40
  */
51
- verify(ser: Uint8Array): boolean {
41
+ verify(ser) {
52
42
  return this._verify(ser, this.raw);
53
43
  }
54
-
55
- compare(ser: Uint8Array, dig: any = null, diger: Diger | null = null) {
44
+ compare(ser, dig = null, diger = null) {
56
45
  if (dig != null) {
57
46
  if (dig.toString() == this.qb64) {
58
47
  return true;
59
48
  }
60
-
61
49
  diger = new Diger({ qb64b: dig });
62
- } else if (diger != null) {
50
+ }
51
+ else if (diger != null) {
63
52
  if (diger.qb64b == this.qb64b) {
64
53
  return true;
65
54
  }
66
- } else {
55
+ }
56
+ else {
67
57
  throw new Error('Both dig and diger may not be None.');
68
58
  }
69
-
70
59
  if (diger.code == this.code) {
71
60
  return false;
72
61
  }
73
-
74
62
  return diger.verify(ser) && this.verify(ser);
75
63
  }
76
-
77
- blake3_256(ser: Uint8Array, dig: any) {
78
- const digest = Buffer.from(
79
- blake3.create({ dkLen: 32 }).update(ser).digest()
80
- );
81
- return digest.toString() === dig.toString();
64
+ blake3_256(ser, dig) {
65
+ const digest = blake3.create({ dkLen: 32 }).update(ser).digest();
66
+ return (digest.length == dig.length && digest.toString() === dig.toString());
82
67
  }
83
68
  }
@@ -1,5 +1,5 @@
1
- import { Matter, MatterArgs } from './matter';
2
- import { Cipher } from './cipher';
1
+ import { Matter, MatterArgs } from './matter.ts';
2
+ import { Cipher } from './cipher.ts';
3
3
  export declare class Encrypter extends Matter {
4
4
  private _encrypt;
5
5
  constructor({ raw, code, qb64, qb64b, qb2 }: MatterArgs, verkey?: Uint8Array | null);
@@ -1,69 +1,49 @@
1
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';
8
-
2
+ import { Matter, MtrDex } from "./matter.js";
3
+ import { Verfer } from "./verfer.js";
4
+ import { Signer } from "./signer.js";
5
+ import { Cipher } from "./cipher.js";
6
+ import { arrayEquals } from "./utils.js";
9
7
  export class Encrypter extends Matter {
10
- private _encrypt: any;
11
- constructor(
12
- { raw, code = MtrDex.X25519, qb64, qb64b, qb2 }: MatterArgs,
13
- verkey: Uint8Array | null = null
14
- ) {
8
+ constructor({ raw, code = MtrDex.X25519, qb64, qb64b, qb2 }, verkey = null) {
15
9
  if (raw == undefined && verkey != null) {
16
10
  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
- );
11
+ if (!Array.from([MtrDex.Ed25519N, MtrDex.Ed25519]).includes(verfer.code)) {
12
+ throw new Error(`Unsupported verkey derivation code = ${verfer.code}.`);
25
13
  }
26
14
  raw = libsodium.crypto_sign_ed25519_pk_to_curve25519(verfer.raw);
27
15
  }
28
-
29
16
  super({ raw, code, qb64, qb64b, qb2 });
30
-
31
17
  if (this.code == MtrDex.X25519) {
32
18
  this._encrypt = this._x25519;
33
- } else {
19
+ }
20
+ else {
34
21
  throw new Error(`Unsupported encrypter code = ${this.code}.`);
35
22
  }
36
23
  }
37
-
38
- verifySeed(seed: Uint8Array) {
24
+ verifySeed(seed) {
39
25
  const signer = new Signer({ qb64b: seed });
40
26
  const keypair = libsodium.crypto_sign_seed_keypair(signer.raw);
41
- const pubkey = libsodium.crypto_sign_ed25519_pk_to_curve25519(
42
- keypair.publicKey
43
- );
27
+ const pubkey = libsodium.crypto_sign_ed25519_pk_to_curve25519(keypair.publicKey);
44
28
  return arrayEquals(pubkey, this.raw);
45
29
  }
46
-
47
- encrypt(ser: Uint8Array | null = null, matter: Matter | null = null) {
30
+ encrypt(ser = null, matter = null) {
48
31
  if (ser == null && matter == null) {
49
32
  throw new Error('Neither ser nor matter are provided.');
50
33
  }
51
-
52
34
  if (ser != null) {
53
35
  matter = new Matter({ qb64b: ser });
54
36
  }
55
-
56
37
  let code;
57
- if (matter!.code == MtrDex.Salt_128) {
38
+ if (matter.code == MtrDex.Salt_128) {
58
39
  code = MtrDex.X25519_Cipher_Salt;
59
- } else {
40
+ }
41
+ else {
60
42
  code = MtrDex.X25519_Cipher_Seed;
61
43
  }
62
-
63
- return this._encrypt(matter!.qb64, this.raw, code);
44
+ return this._encrypt(matter.qb64, this.raw, code);
64
45
  }
65
-
66
- _x25519(ser: Uint8Array, pubkey: Uint8Array, code: string) {
46
+ _x25519(ser, pubkey, code) {
67
47
  const raw = libsodium.crypto_box_seal(ser, pubkey);
68
48
  return new Cipher({ raw: raw, code: code });
69
49
  }
@@ -1,7 +1,7 @@
1
- import { Serials, Version } from './core';
2
- import { Serder } from './serder';
3
- import { Siger } from './siger';
4
- import { Cigar } from './cigar';
1
+ import { Serials, Version } from './core.ts';
2
+ import { Serder } from './serder.ts';
3
+ import { Siger } from './siger.ts';
4
+ import { Cigar } from './cigar.ts';
5
5
  export interface RotateArgs {
6
6
  pre?: string;
7
7
  keys: Array<string>;
@@ -26,9 +26,9 @@ export declare function rotate({ pre, keys, dig, ilk, sn, isith, ndigs, nsith, w
26
26
  export declare function ample(n: number, f?: number, weak?: boolean): number;
27
27
  export interface InceptArgs {
28
28
  keys: Array<string>;
29
- isith?: number | string | Array<string>;
29
+ isith?: string | number | string[] | string[][];
30
30
  ndigs?: Array<string>;
31
- nsith?: number | string | Array<string>;
31
+ nsith?: string | number | string[] | string[][];
32
32
  toad?: number | string;
33
33
  wits?: Array<string>;
34
34
  cnfg?: Array<string>;