signify-ts 0.2.1 → 0.3.0-rc2

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 (128) 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 +34 -14
  7. package/{src/keri/app/aiding.ts → dist/keri/app/aiding.js} +104 -235
  8. package/dist/keri/app/clienting.d.ts +57 -22
  9. package/{src/keri/app/clienting.ts → dist/keri/app/clienting.js} +145 -234
  10. package/dist/keri/app/contacting.d.ts +33 -21
  11. package/{src/keri/app/contacting.ts → dist/keri/app/contacting.js} +25 -62
  12. package/dist/keri/app/controller.d.ts +49 -6
  13. package/{src/keri/app/controller.ts → dist/keri/app/controller.js} +79 -185
  14. package/dist/keri/app/coring.d.ts +30 -8
  15. package/{src/keri/app/coring.ts → dist/keri/app/coring.js} +62 -51
  16. package/dist/keri/app/credentialing.d.ts +183 -65
  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 +1 -1
  21. package/{src/keri/app/escrowing.ts → dist/keri/app/escrowing.js} +2 -8
  22. package/dist/keri/app/exchanging.d.ts +7 -6
  23. package/{src/keri/app/exchanging.ts → dist/keri/app/exchanging.js} +33 -110
  24. package/dist/keri/app/grouping.d.ts +2 -2
  25. package/{src/keri/app/grouping.ts → dist/keri/app/grouping.js} +6 -25
  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 +4 -4
  51. package/{src/keri/core/eventing.ts → dist/keri/core/eventing.js} +134 -321
  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 +98 -46
  57. package/dist/keri/core/keeping.js +365 -0
  58. package/{src/keri/core/kering.ts → dist/keri/core/kering.js} +1 -3
  59. package/dist/keri/core/keyState.d.ts +85 -0
  60. package/dist/keri/core/keyState.js +1 -0
  61. package/dist/keri/core/manager.d.ts +147 -12
  62. package/dist/keri/core/manager.js +880 -0
  63. package/dist/keri/core/matter.d.ts +1 -1
  64. package/dist/keri/core/matter.js +460 -0
  65. package/dist/keri/core/number.d.ts +1 -1
  66. package/{src/keri/core/number.ts → dist/keri/core/number.js} +21 -30
  67. package/dist/keri/core/pather.d.ts +2 -2
  68. package/{src/keri/core/pather.ts → dist/keri/core/pather.js} +12 -27
  69. package/dist/keri/core/prefixer.d.ts +10 -10
  70. package/dist/keri/core/prefixer.js +182 -0
  71. package/dist/keri/core/saider.d.ts +2 -12
  72. package/dist/keri/core/saider.js +107 -0
  73. package/dist/keri/core/salter.d.ts +45 -3
  74. package/dist/keri/core/salter.js +117 -0
  75. package/dist/keri/core/seqner.d.ts +1 -1
  76. package/{src/keri/core/seqner.ts → dist/keri/core/seqner.js} +20 -21
  77. package/dist/keri/core/serder.d.ts +25 -12
  78. package/dist/keri/core/serder.js +133 -0
  79. package/dist/keri/core/siger.d.ts +2 -2
  80. package/{src/keri/core/siger.ts → dist/keri/core/siger.js} +4 -14
  81. package/dist/keri/core/signer.d.ts +4 -4
  82. package/dist/keri/core/signer.js +84 -0
  83. package/{src/keri/core/tholder.ts → dist/keri/core/tholder.js} +69 -94
  84. package/dist/keri/core/utils.d.ts +1 -1
  85. package/{src/keri/core/utils.ts → dist/keri/core/utils.js} +30 -60
  86. package/dist/keri/core/vdring.d.ts +2 -2
  87. package/dist/keri/core/vdring.js +61 -0
  88. package/dist/keri/core/verfer.d.ts +2 -6
  89. package/dist/keri/core/verfer.js +37 -0
  90. package/dist/keri/end/ending.d.ts +10 -8
  91. package/dist/keri/end/ending.js +136 -0
  92. package/{src/ready.ts → dist/ready.js} +1 -2
  93. package/dist/types/keria-api-schema.d.ts +304 -0
  94. package/dist/types/keria-api-schema.js +2 -0
  95. package/package.json +53 -50
  96. package/dist/buffer-polyfill.d.ts +0 -1
  97. package/dist/math.d.ts +0 -1
  98. package/dist/signify-ts.cjs +0 -7842
  99. package/dist/signify-ts.cjs.development.js +0 -9501
  100. package/dist/signify-ts.cjs.development.js.map +0 -1
  101. package/dist/signify-ts.cjs.map +0 -7
  102. package/dist/signify-ts.cjs.production.min.js +0 -2
  103. package/dist/signify-ts.cjs.production.min.js.map +0 -1
  104. package/dist/signify-ts.esm.js +0 -9345
  105. package/dist/signify-ts.esm.js.map +0 -1
  106. package/dist/signify-ts.mjs +0 -7818
  107. package/dist/signify-ts.mjs.map +0 -7
  108. package/src/buffer-polyfill.ts +0 -5
  109. package/src/exports.ts +0 -44
  110. package/src/index.ts +0 -4
  111. package/src/keri/app/credentialing.ts +0 -841
  112. package/src/keri/app/habery.ts +0 -185
  113. package/src/keri/core/cigar.ts +0 -18
  114. package/src/keri/core/core.ts +0 -326
  115. package/src/keri/core/counter.ts +0 -273
  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
@@ -0,0 +1,182 @@
1
+ import { Matter, MtrDex } from "./matter.js";
2
+ import { EmptyMaterialError } from "./kering.js";
3
+ import { Ilks } from "./core.js";
4
+ import { sizeify } from "./serder.js";
5
+ import { Verfer } from "./verfer.js";
6
+ import { blake3 } from '@noble/hashes/blake3';
7
+ const Dummy = '#';
8
+ export class Prefixer extends Matter {
9
+ constructor({ raw, code, qb64b, qb64, qb2 }, ked) {
10
+ try {
11
+ super({ raw, code, qb64b, qb64, qb2 });
12
+ }
13
+ catch (e) {
14
+ if (e instanceof EmptyMaterialError) {
15
+ if (ked == undefined || (code == undefined && !('i' in ked))) {
16
+ throw e;
17
+ }
18
+ if (code == undefined) {
19
+ super({ qb64: ked['i'], code: code });
20
+ code = this.code;
21
+ }
22
+ let _derive;
23
+ if (code == MtrDex.Ed25519N) {
24
+ _derive = Prefixer._derive_ed25519N;
25
+ }
26
+ else if (code == MtrDex.Ed25519) {
27
+ _derive = Prefixer._derive_ed25519;
28
+ }
29
+ else if (code == MtrDex.Blake3_256) {
30
+ _derive = Prefixer._derive_blake3_256;
31
+ }
32
+ else {
33
+ throw new Error(`Unsupported code = ${code} for prefixer.`);
34
+ }
35
+ [raw, code] = _derive(ked);
36
+ super({ raw: raw, code: code });
37
+ this._derive = _derive;
38
+ }
39
+ else {
40
+ throw e;
41
+ }
42
+ }
43
+ if (this.code == MtrDex.Ed25519N) {
44
+ this._verify = this._verify_ed25519N;
45
+ }
46
+ else if (this.code == MtrDex.Ed25519) {
47
+ this._verify = this._verify_ed25519;
48
+ }
49
+ else if (this.code == MtrDex.Blake3_256) {
50
+ this._verify = this._verify_blake3_256;
51
+ }
52
+ else {
53
+ throw new Error(`Unsupported code = ${code} for prefixer.`);
54
+ }
55
+ }
56
+ derive(sad) {
57
+ if (sad['i'] != Ilks.icp) {
58
+ throw new Error(`Non-incepting ilk ${sad['i']} for prefix derivation`);
59
+ }
60
+ return this._derive(sad);
61
+ }
62
+ verify(sad, prefixed = false) {
63
+ if (sad['i'] != Ilks.icp) {
64
+ throw new Error(`Non-incepting ilk ${sad['i']} for prefix derivation`);
65
+ }
66
+ return this._verify(sad, this.qb64, prefixed);
67
+ }
68
+ static _derive_ed25519N(sad) {
69
+ let verfer;
70
+ const keys = sad['k'];
71
+ if (keys.length != 1) {
72
+ throw new Error(`Basic derivation needs at most 1 key got ${keys.length} keys instead`);
73
+ }
74
+ try {
75
+ verfer = new Verfer({ qb64: keys[0] });
76
+ }
77
+ catch (e) {
78
+ throw new Error(`Error extracting public key = ${e}`);
79
+ }
80
+ if (verfer.code != MtrDex.Ed25519N) {
81
+ throw new Error(`Mismatch derivation code = ${verfer.code}`);
82
+ }
83
+ const next = 'n' in sad ? sad['n'] : [];
84
+ if (verfer.code == MtrDex.Ed25519N && next.length > 0) {
85
+ throw new Error(`Non-empty nxt = ${next} for non-transferable code = ${verfer.code}`);
86
+ }
87
+ const backers = 'b' in sad ? sad['b'] : [];
88
+ if (verfer.code == MtrDex.Ed25519N && backers.length > 0) {
89
+ throw new Error(`Non-empty b =${backers} for non-transferable code = ${verfer.code}`);
90
+ }
91
+ const anchor = 'a' in sad ? sad['a'] : [];
92
+ if (verfer.code == MtrDex.Ed25519N && anchor.length > 0) {
93
+ throw new Error(`Non-empty a = ${verfer.code} for non-transferable code = ${verfer.code}`);
94
+ }
95
+ return [verfer.raw, verfer.code];
96
+ }
97
+ static _derive_ed25519(sad) {
98
+ let verfer;
99
+ const keys = sad['k'];
100
+ if (keys.length != 1) {
101
+ throw new Error(`Basic derivation needs at most 1 key got ${keys.length} keys instead`);
102
+ }
103
+ try {
104
+ verfer = new Verfer({ qb64: keys[0] });
105
+ }
106
+ catch (e) {
107
+ throw new Error(`Error extracting public key = ${e}`);
108
+ }
109
+ if (verfer.code in [MtrDex.Ed25519]) {
110
+ throw new Error(`Mismatch derivation code = ${verfer.code}`);
111
+ }
112
+ return [verfer.raw, verfer.code];
113
+ }
114
+ static _derive_blake3_256(sad) {
115
+ const ilk = sad['t'];
116
+ if (![Ilks.icp, Ilks.dip, Ilks.vcp, Ilks.dip].includes(ilk)) {
117
+ throw new Error(`Invalid ilk = ${ilk} to derive pre.`);
118
+ }
119
+ sad['i'] = ''.padStart(Matter.Sizes.get(MtrDex.Blake3_256).fs, Dummy);
120
+ sad['d'] = sad['i'];
121
+ const [raw] = sizeify(sad);
122
+ const dig = blake3.create({ dkLen: 32 }).update(raw).digest();
123
+ return [dig, MtrDex.Blake3_256];
124
+ }
125
+ _verify_ed25519N(sad, pre, prefixed = false) {
126
+ try {
127
+ const keys = sad['k'];
128
+ if (keys.length != 1) {
129
+ return false;
130
+ }
131
+ if (keys[0] != pre) {
132
+ return false;
133
+ }
134
+ if (prefixed && sad['i'] != pre) {
135
+ return false;
136
+ }
137
+ const next = 'n' in sad ? sad['n'] : [];
138
+ if (next.length > 0) {
139
+ // must be empty
140
+ return false;
141
+ }
142
+ }
143
+ catch (e) {
144
+ return false;
145
+ }
146
+ return true;
147
+ }
148
+ _verify_ed25519(sad, pre, prefixed = false) {
149
+ try {
150
+ const keys = sad['k'];
151
+ if (keys.length != 1) {
152
+ return false;
153
+ }
154
+ if (keys[0] != pre) {
155
+ return false;
156
+ }
157
+ if (prefixed && sad['i'] != pre) {
158
+ return false;
159
+ }
160
+ }
161
+ catch (e) {
162
+ return false;
163
+ }
164
+ return true;
165
+ }
166
+ _verify_blake3_256(sad, pre, prefixed = false) {
167
+ try {
168
+ const [raw] = Prefixer._derive_blake3_256(sad);
169
+ const crymat = new Matter({ raw: raw, code: MtrDex.Blake3_256 });
170
+ if (crymat.qb64 != pre) {
171
+ return false;
172
+ }
173
+ if (prefixed && sad['i'] != pre) {
174
+ return false;
175
+ }
176
+ }
177
+ catch (e) {
178
+ return false;
179
+ }
180
+ return true;
181
+ }
182
+ }
@@ -1,23 +1,13 @@
1
- /// <reference types="node" />
2
- import { Matter, MatterArgs } from './matter';
3
- import { Dict, Serials } from './core';
1
+ import { Matter, MatterArgs } from './matter.ts';
2
+ import { Dict, Serials } from './core.ts';
4
3
  export declare enum Ids {
5
4
  d = "d"
6
5
  }
7
- declare class Digestage {
8
- klas: any;
9
- size: number | undefined;
10
- length: number | undefined;
11
- constructor(klas: any, size?: number, length?: number);
12
- }
13
6
  export declare class Saider extends Matter {
14
- static Digests: Map<string, Digestage>;
15
7
  constructor({ raw, code, qb64b, qb64, qb2 }: MatterArgs, sad?: Dict<any>, kind?: Serials, label?: string);
16
- static _derive_blake3_256(ser: Uint8Array, _digest_size: number, _length: number): Buffer;
17
8
  private static _derive;
18
9
  derive(sad: Dict<any>, code: string, kind: Serials | undefined, label: string): [Uint8Array, Dict<any>];
19
10
  verify(sad: Dict<any>, prefixed?: boolean, versioned?: boolean, kind?: Serials, label?: string): boolean;
20
11
  private static _serialze;
21
12
  static saidify(sad: Dict<any>, code?: string, kind?: Serials, label?: string): [Saider, Dict<any>];
22
13
  }
23
- export {};
@@ -0,0 +1,107 @@
1
+ import { DigiDex, Matter, MtrDex } from "./matter.js";
2
+ import { deversify, Serials } from "./core.js";
3
+ import { EmptyMaterialError } from "./kering.js";
4
+ import { dumps, sizeify } from "./serder.js";
5
+ import { blake3 } from '@noble/hashes/blake3';
6
+ const Dummy = '#';
7
+ export var Ids;
8
+ (function (Ids) {
9
+ Ids["d"] = "d";
10
+ })(Ids || (Ids = {}));
11
+ export class Saider extends Matter {
12
+ constructor({ raw, code, qb64b, qb64, qb2 }, sad, kind, label = Ids.d) {
13
+ try {
14
+ super({ raw, code, qb64b, qb64, qb2 });
15
+ }
16
+ catch (e) {
17
+ if (e instanceof EmptyMaterialError) {
18
+ if (sad == undefined || !(label in sad)) {
19
+ throw e;
20
+ }
21
+ if (code == undefined) {
22
+ if (sad[label] != '') {
23
+ super({ qb64: sad[label], code: code });
24
+ code = this.code;
25
+ }
26
+ else {
27
+ code = MtrDex.Blake3_256;
28
+ }
29
+ }
30
+ if (!DigiDex.has(code)) {
31
+ throw new Error(`Unsupported digest code = ${code}`);
32
+ }
33
+ [raw] = Saider._derive(Object.assign({}, sad), code, kind, label);
34
+ super({ raw: raw, code: code });
35
+ }
36
+ else {
37
+ throw e;
38
+ }
39
+ }
40
+ if (!this.digestive) {
41
+ throw new Error(`Unsupported digest code = ${this.code}.`);
42
+ }
43
+ }
44
+ static _derive(sad, code, kind, label) {
45
+ if (!DigiDex.has(code)) {
46
+ throw new Error(`Unsupported digest code = ${code}.`);
47
+ }
48
+ sad = Object.assign({}, sad);
49
+ sad[label] = ''.padStart(Matter.Sizes.get(code).fs, Dummy);
50
+ if ('v' in sad) {
51
+ [, , kind, sad] = sizeify(sad, kind);
52
+ }
53
+ const ser = Object.assign({}, sad);
54
+ const cpa = Saider._serialze(ser, kind);
55
+ switch (code) {
56
+ case MtrDex.Blake3_256:
57
+ return [blake3.create({ dkLen: 32 }).update(cpa).digest(), sad];
58
+ default:
59
+ throw new Error(`Unsupported digest code = ${code}.`);
60
+ }
61
+ }
62
+ derive(sad, code, kind, label) {
63
+ code = code != undefined ? code : this.code;
64
+ return Saider._derive(sad, code, kind, label);
65
+ }
66
+ verify(sad, prefixed = false, versioned = false, kind, label = Ids.d) {
67
+ try {
68
+ const [raw, dsad] = Saider._derive(sad, this.code, kind, label);
69
+ const saider = new Saider({ raw: raw, code: this.code });
70
+ if (this.qb64 != saider.qb64) {
71
+ return false;
72
+ }
73
+ if ('v' in sad && versioned) {
74
+ if (sad['v'] != dsad['v']) {
75
+ return false;
76
+ }
77
+ }
78
+ if (prefixed && sad[label] != this.qb64) {
79
+ return false;
80
+ }
81
+ }
82
+ catch (e) {
83
+ return false;
84
+ }
85
+ return true;
86
+ }
87
+ static _serialze(sad, kind) {
88
+ let knd = Serials.JSON;
89
+ if ('v' in sad) {
90
+ [, knd] = deversify(sad['v']);
91
+ }
92
+ if (kind == undefined) {
93
+ kind = knd;
94
+ }
95
+ return dumps(sad, kind);
96
+ }
97
+ static saidify(sad, code = MtrDex.Blake3_256, kind = Serials.JSON, label = Ids.d) {
98
+ if (!(label in sad)) {
99
+ throw new Error(`Missing id field labeled=${label} in sad.`);
100
+ }
101
+ let raw;
102
+ [raw, sad] = Saider._derive(sad, code, kind, label);
103
+ const saider = new Saider({ raw: raw, code: code }, undefined, kind, label);
104
+ sad[label] = saider.qb64;
105
+ return [saider, sad];
106
+ }
107
+ }
@@ -1,5 +1,8 @@
1
- import { Signer } from './signer';
2
- import { Matter } from './matter';
1
+ import { Signer } from './signer.ts';
2
+ import { Matter } from './matter.ts';
3
+ /**
4
+ * Secret derivation security tier.
5
+ */
3
6
  export declare enum Tier {
4
7
  low = "low",
5
8
  med = "med",
@@ -13,10 +16,49 @@ interface SalterArgs {
13
16
  qb64?: string;
14
17
  qb2?: Uint8Array | undefined;
15
18
  }
19
+ /**
20
+ * Maintains a random salt for secrets (private keys).
21
+ * Its .raw is random salt, .code as cipher suite for salt
22
+ */
16
23
  export declare class Salter extends Matter {
17
24
  private readonly _tier;
18
- constructor({ raw, code, tier, qb64, qb64b, qb2, }: SalterArgs);
25
+ /**
26
+ * Creates a Salter from the provided raw salt bytes or generates a random salt if raw is not provided.
27
+ * Defaults to low security tier. Only supports Salt_128 salt type.
28
+ * @param salterArgs defines the kind of cryptographic seed to create with a variety of raw material initialization sources.
29
+ */
30
+ constructor(salterArgs: SalterArgs);
31
+ /**
32
+ * Stretches the salt to a secret key using the path, .raw, tier, and size determined by self.code.
33
+ *
34
+ * @param size number of bytes of the stretched seed
35
+ * @param path string of bytes prepended (prefixed) to the salt before stretching
36
+ * @param tier security tier for stretching
37
+ * @param temp boolean, True means use temporary, insecure tier; for testing only
38
+ * @returns stretched raw binary seed (secret) derived from path and .raw, and size using argon2d stretching algorithm.
39
+ * @private
40
+ */
19
41
  private stretch;
42
+ /**
43
+ * Returns Signer with the private key secret derived from code the path, the user entered passcode as a salt,
44
+ * and the security tier sized by the CESR cryptographic seed size indicated by the code. See the example below.
45
+ * The Signer's public key for its .verfer is derived from its private key, the Matter code, and the transferable boolean.
46
+ *
47
+ * The construction of the raw hash bytes used looks like this:
48
+ * ( size, password, salt )
49
+ * where
50
+ * ( code size, path, Base64Decode(passcode) )
51
+ * for example, for the initial inception signing key the following parameters are used:
52
+ * ( 32, "signify:controller00", Base64Decode("Athisismysecretkeyseed") )
53
+ * and for the initial rotation key pair the following parameters are used:
54
+ * ( 32, "signify:controller01", Base64Decode("Athisismysecretkeyseed") )
55
+ *
56
+ * @param code derivation code indicating seed type
57
+ * @param transferable whether or not the key is for a transferable or non-transferable identifier.
58
+ * @param path string of bytes prepended (prefixed) to the salt before stretching
59
+ * @param tier security tier for stretching
60
+ * @param temp boolean, True means use temporary, insecure tier; for testing only
61
+ */
20
62
  signer(code?: string, transferable?: boolean, path?: string, tier?: Tier | null, temp?: boolean): Signer;
21
63
  get tier(): Tier | null;
22
64
  }
@@ -0,0 +1,117 @@
1
+ import { Signer } from "./signer.js";
2
+ import { Matter, MtrDex } from "./matter.js";
3
+ import { EmptyMaterialError } from "./kering.js";
4
+ import libsodium from 'libsodium-wrappers-sumo';
5
+ /**
6
+ * Secret derivation security tier.
7
+ */
8
+ export var Tier;
9
+ (function (Tier) {
10
+ Tier["low"] = "low";
11
+ Tier["med"] = "med";
12
+ Tier["high"] = "high";
13
+ })(Tier || (Tier = {}));
14
+ /**
15
+ * Maintains a random salt for secrets (private keys).
16
+ * Its .raw is random salt, .code as cipher suite for salt
17
+ */
18
+ export class Salter extends Matter {
19
+ /**
20
+ * Creates a Salter from the provided raw salt bytes or generates a random salt if raw is not provided.
21
+ * Defaults to low security tier. Only supports Salt_128 salt type.
22
+ * @param salterArgs defines the kind of cryptographic seed to create with a variety of raw material initialization sources.
23
+ */
24
+ constructor(salterArgs) {
25
+ const { raw, code = MtrDex.Salt_128, tier = Tier.low, qb64, qb64b, qb2, } = salterArgs;
26
+ try {
27
+ super({ raw, code, qb64, qb64b, qb2 });
28
+ }
29
+ catch (e) {
30
+ if (e instanceof EmptyMaterialError) {
31
+ if (code == MtrDex.Salt_128) {
32
+ const salt = libsodium.randombytes_buf(libsodium.crypto_pwhash_SALTBYTES);
33
+ super({ raw: salt, code: code });
34
+ }
35
+ else {
36
+ throw new Error('invalid code for Salter, only Salt_128 accepted');
37
+ }
38
+ }
39
+ else {
40
+ throw e;
41
+ }
42
+ }
43
+ if (this.code != MtrDex.Salt_128) {
44
+ throw new Error('invalid code for Salter, only Salt_128 accepted');
45
+ }
46
+ this._tier = tier !== null ? tier : Tier.low;
47
+ }
48
+ /**
49
+ * Stretches the salt to a secret key using the path, .raw, tier, and size determined by self.code.
50
+ *
51
+ * @param size number of bytes of the stretched seed
52
+ * @param path string of bytes prepended (prefixed) to the salt before stretching
53
+ * @param tier security tier for stretching
54
+ * @param temp boolean, True means use temporary, insecure tier; for testing only
55
+ * @returns stretched raw binary seed (secret) derived from path and .raw, and size using argon2d stretching algorithm.
56
+ * @private
57
+ */
58
+ stretch(size = 32, path = '', tier = null, temp = false) {
59
+ tier = tier == null ? this.tier : tier;
60
+ let opslimit, memlimit;
61
+ // Harcoded values based on keripy
62
+ if (temp) {
63
+ opslimit = 1; //libsodium.crypto_pwhash_OPSLIMIT_MIN
64
+ memlimit = 8192; //libsodium.crypto_pwhash_MEMLIMIT_MIN
65
+ }
66
+ else {
67
+ switch (tier) {
68
+ case Tier.low:
69
+ opslimit = 2; //libsodium.crypto_pwhash_OPSLIMIT_INTERACTIVE
70
+ memlimit = 67108864; //libsodium.crypto_pwhash_MEMLIMIT_INTERACTIVE
71
+ break;
72
+ case Tier.med:
73
+ opslimit = 3; //libsodium.crypto_pwhash_OPSLIMIT_MODERATE
74
+ memlimit = 268435456; //libsodium.crypto_pwhash_MEMLIMIT_MODERATE
75
+ break;
76
+ case Tier.high:
77
+ opslimit = 4; //libsodium.crypto_pwhash_OPSLIMIT_SENSITIVE
78
+ memlimit = 1073741824; //libsodium.crypto_pwhash_MEMLIMIT_SENSITIVE
79
+ break;
80
+ default:
81
+ throw new Error(`Unsupported security tier = ${tier}.`);
82
+ }
83
+ }
84
+ return libsodium.crypto_pwhash(size, path, this.raw, opslimit, memlimit, libsodium.crypto_pwhash_ALG_ARGON2ID13);
85
+ }
86
+ /**
87
+ * Returns Signer with the private key secret derived from code the path, the user entered passcode as a salt,
88
+ * and the security tier sized by the CESR cryptographic seed size indicated by the code. See the example below.
89
+ * The Signer's public key for its .verfer is derived from its private key, the Matter code, and the transferable boolean.
90
+ *
91
+ * The construction of the raw hash bytes used looks like this:
92
+ * ( size, password, salt )
93
+ * where
94
+ * ( code size, path, Base64Decode(passcode) )
95
+ * for example, for the initial inception signing key the following parameters are used:
96
+ * ( 32, "signify:controller00", Base64Decode("Athisismysecretkeyseed") )
97
+ * and for the initial rotation key pair the following parameters are used:
98
+ * ( 32, "signify:controller01", Base64Decode("Athisismysecretkeyseed") )
99
+ *
100
+ * @param code derivation code indicating seed type
101
+ * @param transferable whether or not the key is for a transferable or non-transferable identifier.
102
+ * @param path string of bytes prepended (prefixed) to the salt before stretching
103
+ * @param tier security tier for stretching
104
+ * @param temp boolean, True means use temporary, insecure tier; for testing only
105
+ */
106
+ signer(code = MtrDex.Ed25519_Seed, transferable = true, path = '', tier = null, temp = false) {
107
+ const seed = this.stretch(Matter._rawSize(code), path, tier, temp);
108
+ return new Signer({
109
+ raw: seed, // private key
110
+ code: code,
111
+ transferable: transferable,
112
+ });
113
+ }
114
+ get tier() {
115
+ return this._tier;
116
+ }
117
+ }
@@ -1,4 +1,4 @@
1
- import { Matter, MatterArgs } from './matter';
1
+ import { Matter, MatterArgs } from './matter.ts';
2
2
  /**
3
3
  * @description Seqner: subclass of Matter, cryptographic material, for ordinal numbers
4
4
  * such as sequence numbers or first seen ordering numbers.
@@ -1,5 +1,16 @@
1
- import { Matter, MatterArgs, MtrDex } from './matter';
2
- import { intToBytes, bytesToInt } from './utils';
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { Matter, MtrDex } from "./matter.js";
13
+ import { intToBytes, bytesToInt } from "./utils.js";
3
14
  /**
4
15
  * @description Seqner: subclass of Matter, cryptographic material, for ordinal numbers
5
16
  * such as sequence numbers or first seen ordering numbers.
@@ -7,40 +18,28 @@ import { intToBytes, bytesToInt } from './utils';
7
18
  * when provided as attached cryptographic material elements.
8
19
  */
9
20
  export class Seqner extends Matter {
10
- constructor({
11
- raw,
12
- code = MtrDex.Salt_128,
13
- qb64,
14
- qb64b,
15
- qb2,
16
- sn,
17
- snh,
18
- ...kwa
19
- }: MatterArgs & { sn?: number; snh?: string }) {
21
+ constructor(_a) {
22
+ var { raw, code = MtrDex.Salt_128, qb64, qb64b, qb2, sn, snh } = _a, kwa = __rest(_a, ["raw", "code", "qb64", "qb64b", "qb2", "sn", "snh"]);
20
23
  if (!raw && !qb64b && !qb64 && !qb2) {
21
24
  if (sn === undefined) {
22
25
  if (snh === undefined) {
23
26
  sn = 0;
24
- } else {
27
+ }
28
+ else {
25
29
  sn = parseInt(snh, 16);
26
30
  }
27
31
  }
28
-
29
32
  raw = intToBytes(sn, Matter._rawSize(MtrDex.Salt_128));
30
33
  }
31
-
32
- super({ raw, code, qb64, qb64b, qb2, ...kwa });
33
-
34
+ super(Object.assign({ raw, code, qb64, qb64b, qb2 }, kwa));
34
35
  if (this.code !== MtrDex.Salt_128) {
35
36
  throw new Error(`Invalid code = ${this.code} for Seqner.`);
36
37
  }
37
38
  }
38
-
39
- get sn(): number {
39
+ get sn() {
40
40
  return bytesToInt(this.raw); //To check if other readUInt64 is needed
41
41
  }
42
-
43
- get snh(): string {
42
+ get snh() {
44
43
  return this.sn.toString(16);
45
44
  }
46
45
  }
@@ -1,31 +1,44 @@
1
- import { Dict, Ident, Serials, Version } from './core';
2
- import { Verfer } from './verfer';
3
- import { Diger } from './diger';
4
- import { CesrNumber } from './number';
1
+ import { Dict, Protocols, Serials, Version } from './core.ts';
2
+ import { Verfer } from './verfer.ts';
3
+ import { Diger } from './diger.ts';
4
+ import { CesrNumber } from './number.ts';
5
5
  export declare class Serder {
6
6
  private _kind;
7
7
  private _raw;
8
- private _ked;
9
- private _ident;
8
+ private _sad;
9
+ private _proto;
10
10
  private _size;
11
11
  private _version;
12
12
  private readonly _code;
13
- constructor(ked: Dict<any>, kind?: Serials, code?: string);
14
- set ked(ked: Dict<any>);
13
+ /**
14
+ * Creates a new Serder object from a self-addressing data dictionary.
15
+ * @param sad self-addressing data dictionary.
16
+ * @param kind serialization type to produce
17
+ * @param code derivation code for the prefix
18
+ */
19
+ constructor(sad: Dict<any>, kind?: Serials, code?: string);
20
+ get sad(): Dict<any>;
15
21
  get pre(): string;
16
- get ked(): Dict<any>;
17
22
  get code(): string;
18
23
  get raw(): string;
24
+ get said(): string;
19
25
  get sner(): CesrNumber;
20
26
  get sn(): number;
21
27
  get kind(): Serials;
28
+ /**
29
+ * Serializes a self-addressing data dictionary from the dictionary passed in
30
+ * using the specified serialization type.
31
+ * @param sad self-addressing data dictionary.
32
+ * @param kind serialization type to produce
33
+ * @private
34
+ */
22
35
  private _exhale;
23
- get ident(): Ident;
36
+ get proto(): Protocols;
24
37
  get size(): number;
25
38
  get version(): Version;
26
39
  get verfers(): Verfer[];
27
40
  get digers(): Diger[];
28
41
  pretty(): string;
29
42
  }
30
- export declare function dumps(ked: Object, kind: Serials.JSON): string;
31
- export declare function sizeify(ked: Dict<any>, kind?: Serials): [string, Ident, Serials, Dict<any>, Version];
43
+ export declare function dumps(sad: object, kind: Serials.JSON): string;
44
+ export declare function sizeify(ked: Dict<any>, kind?: Serials): [string, Protocols, Serials, Dict<any>, Version];