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
@@ -1,15 +1,15 @@
1
- import { Matter, MatterArgs } from './matter';
2
- import { Dict } from './core';
1
+ import { Matter, MatterArgs } from './matter.ts';
2
+ import { Dict } from './core.ts';
3
3
  export declare class Prefixer extends Matter {
4
4
  private readonly _derive;
5
5
  private readonly _verify;
6
6
  constructor({ raw, code, qb64b, qb64, qb2 }: MatterArgs, ked?: Dict<any>);
7
- derive(ked: Dict<any>): [Uint8Array, string];
8
- verify(ked: Dict<any>, prefixed?: boolean): boolean;
9
- static _derive_ed25519N(ked: Dict<any>): [Uint8Array, string];
10
- static _derive_ed25519(ked: Dict<any>): [Uint8Array, string];
11
- static _derive_blake3_256(ked: Dict<any>): [Uint8Array, string];
12
- _verify_ed25519N(ked: Dict<any>, pre: string, prefixed?: boolean): boolean;
13
- _verify_ed25519(ked: Dict<any>, pre: string, prefixed?: boolean): boolean;
14
- _verify_blake3_256(ked: Dict<any>, pre: string, prefixed?: boolean): boolean;
7
+ derive(sad: Dict<any>): [Uint8Array, string];
8
+ verify(sad: Dict<any>, prefixed?: boolean): boolean;
9
+ static _derive_ed25519N(sad: Dict<any>): [Uint8Array, string];
10
+ static _derive_ed25519(sad: Dict<any>): [Uint8Array, string];
11
+ static _derive_blake3_256(sad: Dict<any>): [Uint8Array, string];
12
+ _verify_ed25519N(sad: Dict<any>, pre: string, prefixed?: boolean): boolean;
13
+ _verify_ed25519(sad: Dict<any>, pre: string, prefixed?: boolean): boolean;
14
+ _verify_blake3_256(sad: Dict<any>, pre: string, prefixed?: boolean): boolean;
15
15
  }
@@ -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,10 +1,7 @@
1
- import { Signer } from './signer';
2
- import { Matter } from './matter';
3
- export declare enum Tier {
4
- low = "low",
5
- med = "med",
6
- high = "high"
7
- }
1
+ import { Signer } from './signer.ts';
2
+ import { Matter } from './matter.ts';
3
+ import { Tier } from '../../types/keria-api-schema.ts';
4
+ export { Tier } from '../../types/keria-api-schema.ts';
8
5
  interface SalterArgs {
9
6
  raw?: Uint8Array | undefined;
10
7
  code?: string;
@@ -13,11 +10,49 @@ interface SalterArgs {
13
10
  qb64?: string;
14
11
  qb2?: Uint8Array | undefined;
15
12
  }
13
+ /**
14
+ * Maintains a random salt for secrets (private keys).
15
+ * Its .raw is random salt, .code as cipher suite for salt
16
+ */
16
17
  export declare class Salter extends Matter {
17
18
  private readonly _tier;
18
- constructor({ raw, code, tier, qb64, qb64b, qb2, }: SalterArgs);
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: SalterArgs);
25
+ /**
26
+ * Stretches the salt to a secret key using the path, .raw, tier, and size determined by self.code.
27
+ *
28
+ * @param size number of bytes of the stretched seed
29
+ * @param path string of bytes prepended (prefixed) to the salt before stretching
30
+ * @param tier security tier for stretching
31
+ * @param temp boolean, True means use temporary, insecure tier; for testing only
32
+ * @returns stretched raw binary seed (secret) derived from path and .raw, and size using argon2d stretching algorithm.
33
+ * @private
34
+ */
19
35
  private stretch;
36
+ /**
37
+ * Returns Signer with the private key secret derived from code the path, the user entered passcode as a salt,
38
+ * and the security tier sized by the CESR cryptographic seed size indicated by the code. See the example below.
39
+ * The Signer's public key for its .verfer is derived from its private key, the Matter code, and the transferable boolean.
40
+ *
41
+ * The construction of the raw hash bytes used looks like this:
42
+ * ( size, password, salt )
43
+ * where
44
+ * ( code size, path, Base64Decode(passcode) )
45
+ * for example, for the initial inception signing key the following parameters are used:
46
+ * ( 32, "signify:controller00", Base64Decode("Athisismysecretkeyseed") )
47
+ * and for the initial rotation key pair the following parameters are used:
48
+ * ( 32, "signify:controller01", Base64Decode("Athisismysecretkeyseed") )
49
+ *
50
+ * @param code derivation code indicating seed type
51
+ * @param transferable whether or not the key is for a transferable or non-transferable identifier.
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
+ */
20
56
  signer(code?: string, transferable?: boolean, path?: string, tier?: Tier | null, temp?: boolean): Signer;
21
57
  get tier(): Tier | null;
22
58
  }
23
- export {};
@@ -0,0 +1,110 @@
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
+ import { Tier } from "../../types/keria-api-schema.js";
6
+ export { Tier } from "../../types/keria-api-schema.js";
7
+ /**
8
+ * Maintains a random salt for secrets (private keys).
9
+ * Its .raw is random salt, .code as cipher suite for salt
10
+ */
11
+ export class Salter extends Matter {
12
+ /**
13
+ * Creates a Salter from the provided raw salt bytes or generates a random salt if raw is not provided.
14
+ * Defaults to low security tier. Only supports Salt_128 salt type.
15
+ * @param salterArgs defines the kind of cryptographic seed to create with a variety of raw material initialization sources.
16
+ */
17
+ constructor(salterArgs) {
18
+ const { raw, code = MtrDex.Salt_128, tier = Tier.low, qb64, qb64b, qb2, } = salterArgs;
19
+ try {
20
+ super({ raw, code, qb64, qb64b, qb2 });
21
+ }
22
+ catch (e) {
23
+ if (e instanceof EmptyMaterialError) {
24
+ if (code == MtrDex.Salt_128) {
25
+ const salt = libsodium.randombytes_buf(libsodium.crypto_pwhash_SALTBYTES);
26
+ super({ raw: salt, code: code });
27
+ }
28
+ else {
29
+ throw new Error('invalid code for Salter, only Salt_128 accepted');
30
+ }
31
+ }
32
+ else {
33
+ throw e;
34
+ }
35
+ }
36
+ if (this.code != MtrDex.Salt_128) {
37
+ throw new Error('invalid code for Salter, only Salt_128 accepted');
38
+ }
39
+ this._tier = tier !== null ? tier : Tier.low;
40
+ }
41
+ /**
42
+ * Stretches the salt to a secret key using the path, .raw, tier, and size determined by self.code.
43
+ *
44
+ * @param size number of bytes of the stretched seed
45
+ * @param path string of bytes prepended (prefixed) to the salt before stretching
46
+ * @param tier security tier for stretching
47
+ * @param temp boolean, True means use temporary, insecure tier; for testing only
48
+ * @returns stretched raw binary seed (secret) derived from path and .raw, and size using argon2d stretching algorithm.
49
+ * @private
50
+ */
51
+ stretch(size = 32, path = '', tier = null, temp = false) {
52
+ tier = tier == null ? this.tier : tier;
53
+ let opslimit, memlimit;
54
+ // Harcoded values based on keripy
55
+ if (temp) {
56
+ opslimit = 1; //libsodium.crypto_pwhash_OPSLIMIT_MIN
57
+ memlimit = 8192; //libsodium.crypto_pwhash_MEMLIMIT_MIN
58
+ }
59
+ else {
60
+ switch (tier) {
61
+ case Tier.low:
62
+ opslimit = 2; //libsodium.crypto_pwhash_OPSLIMIT_INTERACTIVE
63
+ memlimit = 67108864; //libsodium.crypto_pwhash_MEMLIMIT_INTERACTIVE
64
+ break;
65
+ case Tier.med:
66
+ opslimit = 3; //libsodium.crypto_pwhash_OPSLIMIT_MODERATE
67
+ memlimit = 268435456; //libsodium.crypto_pwhash_MEMLIMIT_MODERATE
68
+ break;
69
+ case Tier.high:
70
+ opslimit = 4; //libsodium.crypto_pwhash_OPSLIMIT_SENSITIVE
71
+ memlimit = 1073741824; //libsodium.crypto_pwhash_MEMLIMIT_SENSITIVE
72
+ break;
73
+ default:
74
+ throw new Error(`Unsupported security tier = ${tier}.`);
75
+ }
76
+ }
77
+ return libsodium.crypto_pwhash(size, path, this.raw, opslimit, memlimit, libsodium.crypto_pwhash_ALG_ARGON2ID13);
78
+ }
79
+ /**
80
+ * Returns Signer with the private key secret derived from code the path, the user entered passcode as a salt,
81
+ * and the security tier sized by the CESR cryptographic seed size indicated by the code. See the example below.
82
+ * The Signer's public key for its .verfer is derived from its private key, the Matter code, and the transferable boolean.
83
+ *
84
+ * The construction of the raw hash bytes used looks like this:
85
+ * ( size, password, salt )
86
+ * where
87
+ * ( code size, path, Base64Decode(passcode) )
88
+ * for example, for the initial inception signing key the following parameters are used:
89
+ * ( 32, "signify:controller00", Base64Decode("Athisismysecretkeyseed") )
90
+ * and for the initial rotation key pair the following parameters are used:
91
+ * ( 32, "signify:controller01", Base64Decode("Athisismysecretkeyseed") )
92
+ *
93
+ * @param code derivation code indicating seed type
94
+ * @param transferable whether or not the key is for a transferable or non-transferable identifier.
95
+ * @param path string of bytes prepended (prefixed) to the salt before stretching
96
+ * @param tier security tier for stretching
97
+ * @param temp boolean, True means use temporary, insecure tier; for testing only
98
+ */
99
+ signer(code = MtrDex.Ed25519_Seed, transferable = true, path = '', tier = null, temp = false) {
100
+ const seed = this.stretch(Matter._rawSize(code), path, tier, temp);
101
+ return new Signer({
102
+ raw: seed, // private key
103
+ code: code,
104
+ transferable: transferable,
105
+ });
106
+ }
107
+ get tier() {
108
+ return this._tier;
109
+ }
110
+ }
@@ -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];