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
package/package.json CHANGED
@@ -1,66 +1,68 @@
1
1
  {
2
- "version": "0.1.0",
2
+ "version": "0.2.0",
3
3
  "license": "Apache-2.0",
4
- "main": "dist/index.js",
5
- "typings": "dist/index.d.ts",
4
+ "exports": {
5
+ ".": {
6
+ "import": "./dist/signify-ts.mjs",
7
+ "require": "./dist/signify-ts.cjs",
8
+ "types": "./dist/index.d.ts"
9
+ }
10
+ },
11
+ "types": "./dist/index.d.ts",
12
+ "type": "module",
6
13
  "files": [
7
14
  "dist",
8
15
  "src"
9
16
  ],
10
17
  "scripts": {
11
- "start": "tsdx watch",
12
- "build": "tsdx build",
13
- "test": "tsdx test",
14
- "lint": "tsdx lint",
15
- "prepare": "tsdx build",
16
- "size": "size-limit",
17
- "analyze": "size-limit --why"
18
- },
19
- "husky": {
20
- "hooks": {
21
- "pre-commit": "tsdx lint"
22
- }
23
- },
24
- "prettier": {
25
- "printWidth": 80,
26
- "semi": true,
27
- "singleQuote": true,
28
- "trailingComma": "es5"
18
+ "start": "npm run build:esm -- --watch",
19
+ "build:cjs": "esbuild src/index.ts --bundle --outfile=dist/signify-ts.cjs --platform=neutral --format=cjs --sourcemap --packages=external",
20
+ "build:esm": "esbuild src/index.ts --bundle --outfile=dist/signify-ts.mjs --platform=neutral --format=esm --sourcemap --packages=external",
21
+ "build:types": "tsc -p tsconfig.build.json",
22
+ "build": "npm run build:cjs && npm run build:esm && npm run build:types",
23
+ "test": "jest test/",
24
+ "test:integration": "jest examples/integration-scripts/ --runInBand --bail",
25
+ "lint": "npx eslint src test examples/integration-scripts",
26
+ "prepare": "npm run build",
27
+ "generate-docs": "node_modules/.bin/jsdoc --configure .jsdoc.json --verbose",
28
+ "pretty": "prettier --config .prettierrc 'src/**/*.ts' 'test/**/*.ts' 'examples/**/*.ts' --write",
29
+ "pretty:check": "prettier --config .prettierrc 'src/**/*.ts' 'test/**/*.ts' 'examples/**/*.ts' --check"
29
30
  },
30
31
  "name": "signify-ts",
31
32
  "author": "Phil Feairheller",
32
- "module": "dist/signify-ts.js",
33
- "size-limit": [
34
- {
35
- "path": "dist/signify-ts.cjs.production.min.js",
36
- "limit": "10 KB"
37
- },
38
- {
39
- "path": "dist/signify-ts.esm.js",
40
- "limit": "10 KB"
41
- }
42
- ],
43
33
  "devDependencies": {
44
- "@size-limit/preset-small-lib": "^5.0.4",
45
- "@types/lodash": "^4.14.185",
34
+ "@mermaid-js/mermaid-cli": "^10.3.0",
35
+ "@types/jest": "^29.5.8",
36
+ "@types/libsodium-wrappers-sumo": "^0.7.5",
37
+ "@types/node": "^18.11.18",
46
38
  "@types/urlsafe-base64": "^1.0.28",
47
- "husky": "^7.0.2",
39
+ "@typescript-eslint/eslint-plugin": "^6.10.0",
40
+ "@typescript-eslint/parser": "^6.10.0",
41
+ "esbuild": "^0.19.5",
42
+ "eslint": "^8.53.0",
43
+ "eslint-config-prettier": "^9.0.0",
48
44
  "jest": "^29.3.1",
49
- "size-limit": "^5.0.4",
50
- "ts-migrate": "^0.1.23",
51
- "tsdx": "^0.14.1",
52
- "tslib": "^2.3.1",
53
- "typescript": "^4.4.3"
45
+ "jest-fetch-mock": "^3.0.3",
46
+ "jsdoc": "^4.0.2",
47
+ "minami": "^1.2.3",
48
+ "prettier": "^3.0.3",
49
+ "ts-jest": "^29.1.1",
50
+ "ts-mockito": "^2.6.1",
51
+ "ts-node": "^10.9.1",
52
+ "typedoc": "^0.25.3",
53
+ "typescript": "^5.2.2",
54
+ "whatwg-fetch": "^3.6.19"
54
55
  },
55
56
  "dependencies": {
56
- "@types/libsodium-wrappers-sumo": "^0.7.5",
57
- "blake3": "^2.1.7",
58
- "cbor": "^8.0.0",
59
- "collections": "^5.1.12",
57
+ "@noble/hashes": "^1.3.2",
58
+ "buffer": "^6.0.3",
59
+ "ecdsa-secp256r1": "^1.3.3",
60
60
  "libsodium-wrappers-sumo": "^0.7.9",
61
- "lodash": "^4.17.21",
62
- "msgpack5": "^5.3.2",
63
- "urlsafe-base64": "^1.0.0",
64
- "xregexp": "^5.1.0"
65
- }
61
+ "mathjs": "^11.8.2",
62
+ "structured-headers": "^0.5.0",
63
+ "urlsafe-base64": "^1.0.0"
64
+ },
65
+ "workspaces": [
66
+ "examples/*"
67
+ ]
66
68
  }
@@ -0,0 +1,5 @@
1
+ import { Buffer } from 'buffer';
2
+
3
+ try {
4
+ window.Buffer = Buffer;
5
+ } catch (e) {}
package/src/exports.ts ADDED
@@ -0,0 +1,44 @@
1
+ export * from './ready';
2
+ export * from './math';
3
+
4
+ export * from './keri/app/habery';
5
+ export * from './keri/app/controller';
6
+
7
+ export * from './keri/app/aiding';
8
+ export * from './keri/app/clienting';
9
+ export * from './keri/app/contacting';
10
+ export * from './keri/app/coring';
11
+ export * from './keri/app/credentialing';
12
+ export * from './keri/app/escrowing';
13
+ export * from './keri/app/exchanging';
14
+ export * from './keri/app/grouping';
15
+ export * from './keri/app/notifying';
16
+
17
+ export * from './keri/core/authing';
18
+ export * from './keri/core/cigar';
19
+ export * from './keri/core/cipher';
20
+ export * from './keri/core/core';
21
+ export * from './keri/core/counter';
22
+ export * from './keri/core/decrypter';
23
+ export * from './keri/core/diger';
24
+ export * from './keri/core/encrypter';
25
+ export * from './keri/core/eventing';
26
+ export * from './keri/core/httping';
27
+ export * from './keri/core/indexer';
28
+ export * from './keri/core/keeping';
29
+ export * from './keri/core/kering';
30
+ export * from './keri/core/manager';
31
+ export * from './keri/core/matter';
32
+ export * from './keri/core/number';
33
+ export * from './keri/core/prefixer';
34
+ export * from './keri/core/saider';
35
+ export * from './keri/core/salter';
36
+ export * from './keri/core/seqner';
37
+ export * from './keri/core/serder';
38
+ export * from './keri/core/siger';
39
+ export * from './keri/core/signer';
40
+ export * from './keri/core/tholder';
41
+ export * from './keri/core/utils';
42
+ export * from './keri/core/verfer';
43
+
44
+ export * from './keri/end/ending';
package/src/index.ts CHANGED
@@ -1,6 +1,4 @@
1
- export const sum = (a: number, b: number) => {
2
- if ('development' === process.env.NODE_ENV) {
3
- console.log('boop');
4
- }
5
- return a + b;
6
- };
1
+ import './buffer-polyfill';
2
+ import * as exp from './exports';
3
+ export * from './exports';
4
+ export default exp;
@@ -0,0 +1,493 @@
1
+ import { Tier } from '../core/salter';
2
+ import { Algos } from '../core/manager';
3
+ import { incept, interact, reply, rotate } from '../core/eventing';
4
+ import { b, Ilks, Serials, Versionage } from '../core/core';
5
+ import { Tholder } from '../core/tholder';
6
+ import { MtrDex } from '../core/matter';
7
+ import { Serder } from '../core/serder';
8
+ import { parseRangeHeaders } from '../core/httping';
9
+ import { KeyManager } from '../core/keeping';
10
+
11
+ /** Arguments required to create an identfier */
12
+ export interface CreateIdentiferArgs {
13
+ transferable?: boolean;
14
+ isith?: string | number | string[];
15
+ nsith?: string | number | string[];
16
+ wits?: string[];
17
+ toad?: number;
18
+ proxy?: string;
19
+ delpre?: string;
20
+ dcode?: string;
21
+ data?: any;
22
+ algo?: Algos;
23
+ pre?: string;
24
+ states?: any[];
25
+ rstates?: any[];
26
+ prxs?: any[];
27
+ nxts?: any[];
28
+ mhab?: any;
29
+ keys?: any[];
30
+ ndigs?: any[];
31
+ bran?: string;
32
+ count?: number;
33
+ ncount?: number;
34
+ tier?: Tier;
35
+ extern_type?: string;
36
+ extern?: any;
37
+ }
38
+
39
+ /** Arguments required to rotate an identfier */
40
+ export interface RotateIdentifierArgs {
41
+ transferable?: boolean;
42
+ nsith?: string | number | string[];
43
+ toad?: number;
44
+ cuts?: string[];
45
+ adds?: string[];
46
+ data?: Array<object>;
47
+ ncode?: string;
48
+ ncount?: number;
49
+ ncodes?: string[];
50
+ states?: any[];
51
+ rstates?: any[];
52
+ }
53
+
54
+ /**
55
+ * Reducing the SignifyClient dependencies used by Identifier class
56
+ */
57
+ export interface IdentifierDeps {
58
+ fetch(
59
+ pathname: string,
60
+ method: string,
61
+ body: unknown,
62
+ headers?: Headers
63
+ ): Promise<Response>;
64
+ pidx: number;
65
+ manager: KeyManager | null;
66
+ }
67
+
68
+ /** Identifier */
69
+ export class Identifier {
70
+ public client: IdentifierDeps;
71
+
72
+ /**
73
+ * Identifier
74
+ * @param {IdentifierDeps} client
75
+ */
76
+ constructor(client: IdentifierDeps) {
77
+ this.client = client;
78
+ }
79
+
80
+ /**
81
+ * List managed identifiers
82
+ * @async
83
+ * @param {number} [start=0] Start index of list of notifications, defaults to 0
84
+ * @param {number} [end=24] End index of list of notifications, defaults to 24
85
+ * @returns {Promise<any>} A promise to the list of managed identifiers
86
+ */
87
+ async list(start: number = 0, end: number = 24): Promise<any> {
88
+ const extraHeaders = new Headers();
89
+ extraHeaders.append('Range', `aids=${start}-${end}`);
90
+
91
+ const path = `/identifiers`;
92
+ const data = null;
93
+ const method = 'GET';
94
+ const res = await this.client.fetch(path, method, data, extraHeaders);
95
+
96
+ const cr = res.headers.get('content-range');
97
+ const range = parseRangeHeaders(cr, 'aids');
98
+ const aids = await res.json();
99
+
100
+ return {
101
+ start: range.start,
102
+ end: range.end,
103
+ total: range.total,
104
+ aids: aids,
105
+ };
106
+ }
107
+
108
+ /**
109
+ * Get information for a managed identifier
110
+ * @async
111
+ * @param {string} name Name or alias of the identifier
112
+ * @returns {Promise<any>} A promise to the identifier information
113
+ */
114
+ async get(name: string): Promise<any> {
115
+ const path = `/identifiers/${name}`;
116
+ const data = null;
117
+ const method = 'GET';
118
+ const res = await this.client.fetch(path, method, data);
119
+ return await res.json();
120
+ }
121
+
122
+ /**
123
+ * Create a managed identifier
124
+ * @async
125
+ * @param {string} name Name or alias of the identifier
126
+ * @param {CreateIdentiferArgs} [kargs] Optional parameters to create the identifier
127
+ * @returns {EventResult} The inception result
128
+ */
129
+ async create(
130
+ name: string,
131
+ kargs: CreateIdentiferArgs = {}
132
+ ): Promise<EventResult> {
133
+ const algo = kargs.algo == undefined ? Algos.salty : kargs.algo;
134
+
135
+ const transferable = kargs.transferable ?? true;
136
+ const isith = kargs.isith ?? '1';
137
+ const nsith = kargs.nsith ?? '1';
138
+ let wits = kargs.wits ?? [];
139
+ const toad = kargs.toad ?? 0;
140
+ const dcode = kargs.dcode ?? MtrDex.Blake3_256;
141
+ const proxy = kargs.proxy;
142
+ const delpre = kargs.delpre;
143
+ const data = kargs.data != undefined ? [kargs.data] : [];
144
+ const pre = kargs.pre;
145
+ const states = kargs.states;
146
+ const rstates = kargs.rstates;
147
+ const prxs = kargs.prxs;
148
+ const nxts = kargs.nxts;
149
+ const mhab = kargs.mhab;
150
+ const _keys = kargs.keys;
151
+ const _ndigs = kargs.ndigs;
152
+ const bran = kargs.bran;
153
+ const count = kargs.count;
154
+ const ncount = kargs.ncount;
155
+ const tier = kargs.tier;
156
+ const extern_type = kargs.extern_type;
157
+ const extern = kargs.extern;
158
+
159
+ const xargs = {
160
+ transferable: transferable,
161
+ isith: isith,
162
+ nsith: nsith,
163
+ wits: wits,
164
+ toad: toad,
165
+ proxy: proxy,
166
+ delpre: delpre,
167
+ dcode: dcode,
168
+ data: data,
169
+ algo: algo,
170
+ pre: pre,
171
+ prxs: prxs,
172
+ nxts: nxts,
173
+ mhab: mhab,
174
+ states: states,
175
+ rstates: rstates,
176
+ keys: _keys,
177
+ ndigs: _ndigs,
178
+ bran: bran,
179
+ count: count,
180
+ ncount: ncount,
181
+ tier: tier,
182
+ extern_type: extern_type,
183
+ extern: extern,
184
+ };
185
+
186
+ const keeper = this.client.manager!.new(algo, this.client.pidx, xargs);
187
+ const [keys, ndigs] = await keeper!.incept(transferable);
188
+ wits = wits !== undefined ? wits : [];
189
+ let serder: Serder | undefined = undefined;
190
+ if (delpre == undefined) {
191
+ serder = incept({
192
+ keys: keys!,
193
+ isith: isith,
194
+ ndigs: ndigs,
195
+ nsith: nsith,
196
+ toad: toad,
197
+ wits: wits,
198
+ cnfg: [],
199
+ data: data,
200
+ version: Versionage,
201
+ kind: Serials.JSON,
202
+ code: dcode,
203
+ intive: false,
204
+ });
205
+ } else {
206
+ serder = incept({
207
+ keys: keys!,
208
+ isith: isith,
209
+ ndigs: ndigs,
210
+ nsith: nsith,
211
+ toad: toad,
212
+ wits: wits,
213
+ cnfg: [],
214
+ data: data,
215
+ version: Versionage,
216
+ kind: Serials.JSON,
217
+ code: dcode,
218
+ intive: false,
219
+ delpre: delpre,
220
+ });
221
+ }
222
+
223
+ const sigs = await keeper!.sign(b(serder.raw));
224
+ const jsondata: any = {
225
+ name: name,
226
+ icp: serder.ked,
227
+ sigs: sigs,
228
+ proxy: proxy,
229
+ smids:
230
+ states != undefined
231
+ ? states.map((state) => state.i)
232
+ : undefined,
233
+ rmids:
234
+ rstates != undefined
235
+ ? rstates.map((state) => state.i)
236
+ : undefined,
237
+ };
238
+ jsondata[algo] = keeper.params();
239
+
240
+ this.client.pidx = this.client.pidx + 1;
241
+ const res = this.client.fetch('/identifiers', 'POST', jsondata);
242
+ return new EventResult(serder, sigs, res);
243
+ }
244
+
245
+ /**
246
+ * Generate an interaction event in a managed identifier
247
+ * @async
248
+ * @param {string} name Name or alias of the identifier
249
+ * @param {any} [data] Option data to be anchored in the interaction event
250
+ * @returns {Promise<EventResult>} A promise to the interaction event result
251
+ */
252
+ async interact(name: string, data?: any): Promise<EventResult> {
253
+ const hab = await this.get(name);
254
+ const pre: string = hab.prefix;
255
+
256
+ const state = hab.state;
257
+ const sn = Number(state.s);
258
+ const dig = state.d;
259
+
260
+ data = Array.isArray(data) ? data : [data];
261
+
262
+ data = Array.isArray(data) ? data : [data];
263
+
264
+ const serder = interact({
265
+ pre: pre,
266
+ sn: sn + 1,
267
+ data: data,
268
+ dig: dig,
269
+ version: undefined,
270
+ kind: undefined,
271
+ });
272
+ const keeper = this.client!.manager!.get(hab);
273
+ const sigs = await keeper.sign(b(serder.raw));
274
+
275
+ const jsondata: any = {
276
+ ixn: serder.ked,
277
+ sigs: sigs,
278
+ };
279
+ jsondata[keeper.algo] = keeper.params();
280
+
281
+ const res = await this.client.fetch(
282
+ '/identifiers/' + name + '?type=ixn',
283
+ 'PUT',
284
+ jsondata
285
+ );
286
+ return new EventResult(serder, sigs, res);
287
+ }
288
+
289
+ /**
290
+ * Generate a rotation event in a managed identifier
291
+ * @param {string} name Name or alias of the identifier
292
+ * @param {RotateIdentifierArgs} [kargs] Optional parameters requiered to generate the rotation event
293
+ * @returns {Promise<EventResult>} A promise to the rotation event result
294
+ */
295
+ async rotate(
296
+ name: string,
297
+ kargs: RotateIdentifierArgs = {}
298
+ ): Promise<EventResult> {
299
+ const transferable = kargs.transferable ?? true;
300
+ const ncode = kargs.ncode ?? MtrDex.Ed25519_Seed;
301
+ const ncount = kargs.ncount ?? 1;
302
+
303
+ const hab = await this.get(name);
304
+ const pre = hab.prefix;
305
+ const delegated = hab.state.di !== '';
306
+
307
+ const state = hab.state;
308
+ const count = state.k.length;
309
+ const dig = state.d;
310
+ const ridx = Number(state.s) + 1;
311
+ const wits = state.b;
312
+ let isith = state.nt;
313
+
314
+ let nsith = kargs.nsith ?? isith;
315
+
316
+ // if isith is None: # compute default from newly rotated verfers above
317
+ if (isith == undefined)
318
+ isith = `${Math.max(1, Math.ceil(count / 2)).toString(16)}`;
319
+
320
+ // if nsith is None: # compute default from newly rotated digers above
321
+ if (nsith == undefined)
322
+ nsith = `${Math.max(1, Math.ceil(ncount / 2)).toString(16)}`;
323
+
324
+ const cst = new Tholder({ sith: isith }).sith; // current signing threshold
325
+ const nst = new Tholder({ sith: nsith }).sith; // next signing threshold
326
+
327
+ // Regenerate next keys to sign rotation event
328
+ const keeper = this.client.manager!.get(hab);
329
+ // Create new keys for next digests
330
+ const ncodes = kargs.ncodes ?? new Array(ncount).fill(ncode);
331
+
332
+ const states = kargs.states == undefined ? [] : kargs.states;
333
+ const rstates = kargs.rstates == undefined ? [] : kargs.rstates;
334
+ const [keys, ndigs] = await keeper!.rotate(
335
+ ncodes,
336
+ transferable,
337
+ states,
338
+ rstates
339
+ );
340
+
341
+ const cuts = kargs.cuts ?? [];
342
+ const adds = kargs.adds ?? [];
343
+ const data = kargs.data != undefined ? [kargs.data] : [];
344
+ const toad = kargs.toad;
345
+ const ilk = delegated ? Ilks.drt : Ilks.rot;
346
+
347
+ const serder = rotate({
348
+ pre: pre,
349
+ ilk: ilk,
350
+ keys: keys,
351
+ dig: dig,
352
+ sn: ridx,
353
+ isith: cst,
354
+ nsith: nst,
355
+ ndigs: ndigs,
356
+ toad: toad,
357
+ wits: wits,
358
+ cuts: cuts,
359
+ adds: adds,
360
+ data: data,
361
+ });
362
+
363
+ const sigs = await keeper.sign(b(serder.raw));
364
+
365
+ const jsondata: any = {
366
+ rot: serder.ked,
367
+ sigs: sigs,
368
+ smids:
369
+ states != undefined
370
+ ? states.map((state) => state.i)
371
+ : undefined,
372
+ rmids:
373
+ rstates != undefined
374
+ ? rstates.map((state) => state.i)
375
+ : undefined,
376
+ };
377
+ jsondata[keeper.algo] = keeper.params();
378
+
379
+ const res = await this.client.fetch(
380
+ '/identifiers/' + name,
381
+ 'PUT',
382
+ jsondata
383
+ );
384
+ return new EventResult(serder, sigs, res);
385
+ }
386
+
387
+ /**
388
+ * Authorize an endpoint provider in a given role for a managed identifier
389
+ * @remarks
390
+ * Typically used to authorize the agent to be the endpoint provider for the identifier in the role of `agent`
391
+ * @async
392
+ * @param {string} name Name or alias of the identifier
393
+ * @param {string} role Authorized role for eid
394
+ * @param {string} [eid] Optional qb64 of endpoint provider to be authorized
395
+ * @param {string} [stamp=now] Optional date-time-stamp RFC-3339 profile of iso8601 datetime. Now is the default if not provided
396
+ * @returns {Promise<EventResult>} A promise to the result of the authorization
397
+ */
398
+ async addEndRole(
399
+ name: string,
400
+ role: string,
401
+ eid?: string,
402
+ stamp?: string
403
+ ): Promise<EventResult> {
404
+ const hab = await this.get(name);
405
+ const pre = hab.prefix;
406
+
407
+ const rpy = this.makeEndRole(pre, role, eid, stamp);
408
+ const keeper = this.client.manager!.get(hab);
409
+ const sigs = await keeper.sign(b(rpy.raw));
410
+
411
+ const jsondata = {
412
+ rpy: rpy.ked,
413
+ sigs: sigs,
414
+ };
415
+
416
+ const res = this.client.fetch(
417
+ '/identifiers/' + name + '/endroles',
418
+ 'POST',
419
+ jsondata
420
+ );
421
+ return new EventResult(rpy, sigs, res);
422
+ }
423
+
424
+ /**
425
+ * Generate an /end/role/add reply message
426
+ * @param {string} pre Prefix of the identifier
427
+ * @param {string} role Authorized role for eid
428
+ * @param {string} [eid] Optional qb64 of endpoint provider to be authorized
429
+ * @param {string} [stamp=now] Optional date-time-stamp RFC-3339 profile of iso8601 datetime. Now is the default if not provided
430
+ * @returns {Serder} The reply message
431
+ */
432
+ private makeEndRole(
433
+ pre: string,
434
+ role: string,
435
+ eid?: string,
436
+ stamp?: string
437
+ ): Serder {
438
+ const data: any = {
439
+ cid: pre,
440
+ role: role,
441
+ };
442
+ if (eid != undefined) {
443
+ data.eid = eid;
444
+ }
445
+ const route = '/end/role/add';
446
+ return reply(route, data, stamp, undefined, Serials.JSON);
447
+ }
448
+
449
+ /**
450
+ * Get the members of a group identifier
451
+ * @async
452
+ * @param {string} name - Name or alias of the identifier
453
+ * @returns {Promise<any>} - A promise to the list of members
454
+ */
455
+ async members(name: string): Promise<any> {
456
+ const res = await this.client.fetch(
457
+ '/identifiers/' + name + '/members',
458
+ 'GET',
459
+ undefined
460
+ );
461
+ return await res.json();
462
+ }
463
+ }
464
+
465
+ /** Event Result */
466
+ export class EventResult {
467
+ private readonly _serder: Serder;
468
+ private readonly _sigs: string[];
469
+ private readonly promise: Promise<Response> | Response;
470
+
471
+ constructor(
472
+ serder: Serder,
473
+ sigs: string[],
474
+ promise: Promise<Response> | Response
475
+ ) {
476
+ this._serder = serder;
477
+ this._sigs = sigs;
478
+ this.promise = promise;
479
+ }
480
+
481
+ get serder() {
482
+ return this._serder;
483
+ }
484
+
485
+ get sigs() {
486
+ return this._sigs;
487
+ }
488
+
489
+ async op(): Promise<any> {
490
+ const res = await this.promise;
491
+ return await res.json();
492
+ }
493
+ }