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
@@ -1,25 +1,20 @@
1
- import { SignifyClient } from './clienting';
2
- import { b, d, Dict, Ident, Ilks, Serials, versify } from '../core/core';
3
- import { Serder } from '../core/serder';
4
- import { nowUTC } from '../core/utils';
5
- import { Pather } from '../core/pather';
6
- import { Counter, CtrDex } from '../core/counter';
7
- import { Saider } from '../core/saider';
8
-
1
+ import { b, d, Protocols, Ilks, Serials, versify } from "../core/core.js";
2
+ import { Serder } from "../core/serder.js";
3
+ import { nowUTC } from "../core/utils.js";
4
+ import { Pather } from "../core/pather.js";
5
+ import { Counter, CtrDex } from "../core/counter.js";
6
+ import { Saider } from "../core/saider.js";
9
7
  /**
10
8
  * Exchanges
11
9
  */
12
10
  export class Exchanges {
13
- client: SignifyClient;
14
-
15
11
  /**
16
12
  * Exchanges
17
13
  * @param {SignifyClient} client
18
14
  */
19
- constructor(client: SignifyClient) {
15
+ constructor(client) {
20
16
  this.client = client;
21
17
  }
22
-
23
18
  /**
24
19
  * Create exn message
25
20
  * @async
@@ -32,31 +27,12 @@ export class Exchanges {
32
27
  * @param datetime
33
28
  * @param dig
34
29
  */
35
- async createExchangeMessage(
36
- sender: Dict<any>,
37
- route: string,
38
- payload: Dict<any>,
39
- embeds: Dict<any>,
40
- recipient?: string,
41
- datetime?: string,
42
- dig?: string
43
- ): Promise<[Serder, string[], string]> {
44
- const keeper = this.client.manager!.get(sender);
45
- const [exn, end] = exchange(
46
- route,
47
- payload,
48
- sender['prefix'],
49
- recipient,
50
- datetime,
51
- dig,
52
- undefined,
53
- embeds
54
- );
55
-
30
+ async createExchangeMessage(sender, route, payload, embeds, recipient, datetime, dig) {
31
+ const keeper = this.client.manager.get(sender);
32
+ const [exn, end] = exchange(route, payload, sender['prefix'], recipient, datetime, dig, undefined, embeds);
56
33
  const sigs = await keeper.sign(b(exn.raw));
57
34
  return [exn, sigs, d(end)];
58
35
  }
59
-
60
36
  /**
61
37
  * Send exn messages to list of recipients
62
38
  * @async
@@ -69,31 +45,12 @@ export class Exchanges {
69
45
  * @param embeds
70
46
  * @param recipients
71
47
  */
72
- async send(
73
- name: string,
74
- topic: string,
75
- sender: Dict<any>,
76
- route: string,
77
- payload: Dict<any>,
78
- embeds: Dict<any>,
79
- recipients: string[]
80
- ): Promise<any> {
81
- const [exn, sigs, atc] = await this.createExchangeMessage(
82
- sender,
83
- route,
84
- payload,
85
- embeds
86
- );
87
- return await this.sendFromEvents(
88
- name,
89
- topic,
90
- exn,
91
- sigs,
92
- atc,
93
- recipients
94
- );
48
+ async send(name, topic, sender, route, payload, embeds, recipients) {
49
+ for (const recipient of recipients) {
50
+ const [exn, sigs, atc] = await this.createExchangeMessage(sender, route, payload, embeds, recipient);
51
+ return await this.sendFromEvents(name, topic, exn, sigs, atc, recipients);
52
+ }
95
53
  }
96
-
97
54
  /**
98
55
  * Send exn messaget to list of recipients
99
56
  * @async
@@ -105,69 +62,47 @@ export class Exchanges {
105
62
  * @param atc
106
63
  * @param recipients
107
64
  */
108
- async sendFromEvents(
109
- name: string,
110
- topic: string,
111
- exn: Serder,
112
- sigs: string[],
113
- atc: string,
114
- recipients: string[]
115
- ): Promise<any> {
65
+ async sendFromEvents(name, topic, exn, sigs, atc, recipients) {
116
66
  const path = `/identifiers/${name}/exchanges`;
117
67
  const method = 'POST';
118
- const data: any = {
68
+ const data = {
119
69
  tpc: topic,
120
- exn: exn.ked,
70
+ exn: exn.sad,
121
71
  sigs: sigs,
122
72
  atc: atc,
123
73
  rec: recipients,
124
74
  };
125
-
126
75
  const res = await this.client.fetch(path, method, data);
127
76
  return await res.json();
128
77
  }
129
-
130
78
  /**
131
79
  * Get exn message by said
132
80
  * @async
133
81
  * @returns A promise to the exn message
134
82
  * @param said The said of the exn message
135
83
  */
136
- async get(said: string): Promise<any> {
84
+ async get(said) {
137
85
  const path = `/exchanges/${said}`;
138
86
  const method = 'GET';
139
87
  const res = await this.client.fetch(path, method, null);
140
88
  return await res.json();
141
89
  }
142
90
  }
143
-
144
- export function exchange(
145
- route: string,
146
- payload: Dict<any>,
147
- sender: string,
148
- recipient?: string,
149
- date?: string,
150
- dig?: string,
151
- modifiers?: Dict<any>,
152
- embeds?: Dict<any>
153
- ): [Serder, Uint8Array] {
154
- const vs = versify(Ident.KERI, undefined, Serials.JSON, 0);
91
+ export function exchange(route, payload, sender, recipient, date, dig, modifiers, embeds) {
92
+ const vs = versify(Protocols.KERI, undefined, Serials.JSON, 0);
155
93
  const ilk = Ilks.exn;
156
- const dt =
157
- date !== undefined
158
- ? date
159
- : nowUTC().toISOString().replace('Z', '000+00:00');
94
+ const dt = date !== undefined
95
+ ? date
96
+ : nowUTC().toISOString().replace('Z', '000+00:00');
160
97
  const p = dig !== undefined ? dig : '';
161
98
  const q = modifiers !== undefined ? modifiers : {};
162
99
  const ems = embeds != undefined ? embeds : {};
163
-
164
- let e = {} as Dict<any>;
100
+ let e = {};
165
101
  let end = '';
166
102
  Object.entries(ems).forEach(([key, value]) => {
167
103
  const serder = value[0];
168
104
  const atc = value[1];
169
- e[key] = serder.ked;
170
-
105
+ e[key] = serder.sad;
171
106
  if (atc == undefined) {
172
107
  return;
173
108
  }
@@ -175,7 +110,6 @@ export function exchange(
175
110
  const pather = new Pather({}, undefined, ['e', key]);
176
111
  pathed += pather.qb64;
177
112
  pathed += atc;
178
-
179
113
  const counter = new Counter({
180
114
  code: CtrDex.PathedMaterialQuadlets,
181
115
  count: Math.floor(pathed.length / 4),
@@ -183,28 +117,19 @@ export function exchange(
183
117
  end += counter.qb64;
184
118
  end += pathed;
185
119
  });
186
-
187
120
  if (Object.keys(e).length > 0) {
188
121
  e['d'] = '';
189
122
  [, e] = Saider.saidify(e);
190
123
  }
191
-
192
- const attrs = {} as Dict<any>;
193
-
194
- if (recipient !== undefined) {
195
- attrs['i'] = recipient;
196
- }
197
-
198
- const a = {
199
- ...attrs,
200
- ...payload,
201
- };
202
-
203
- const _ked = {
124
+ const attrs = {};
125
+ attrs['i'] = recipient;
126
+ const a = Object.assign(Object.assign({}, attrs), payload);
127
+ const _sad = {
204
128
  v: vs,
205
129
  t: ilk,
206
130
  d: '',
207
131
  i: sender,
132
+ rp: recipient,
208
133
  p: p,
209
134
  dt: dt,
210
135
  r: route,
@@ -212,9 +137,7 @@ export function exchange(
212
137
  a: a,
213
138
  e: e,
214
139
  };
215
- const [, ked] = Saider.saidify(_ked);
216
-
217
- const exn = new Serder(ked);
218
-
140
+ const [, sad] = Saider.saidify(_sad);
141
+ const exn = new Serder(sad);
219
142
  return [exn, b(end)];
220
143
  }
@@ -1,5 +1,5 @@
1
- import { SignifyClient } from './clienting';
2
- import { Dict } from '../core/core';
1
+ import { SignifyClient } from './clienting.ts';
2
+ import { Dict } from '../core/core.ts';
3
3
  /**
4
4
  * Groups
5
5
  */
@@ -1,33 +1,26 @@
1
- import { SignifyClient } from './clienting';
2
- import { Dict } from '../core/core';
3
-
4
1
  /**
5
2
  * Groups
6
3
  */
7
4
  export class Groups {
8
- client: SignifyClient;
9
-
10
5
  /**
11
6
  * Groups
12
7
  * @param {SignifyClient} client
13
8
  */
14
- constructor(client: SignifyClient) {
9
+ constructor(client) {
15
10
  this.client = client;
16
11
  }
17
-
18
12
  /**
19
13
  * Get group request messages
20
14
  * @async
21
15
  * @param {string} [said] SAID of exn message to load
22
16
  * @returns {Promise<any>} A promise to the list of replay messages
23
17
  */
24
- async getRequest(said: string): Promise<any> {
18
+ async getRequest(said) {
25
19
  const path = `/multisig/request/` + said;
26
20
  const method = 'GET';
27
21
  const res = await this.client.fetch(path, method, null);
28
22
  return await res.json();
29
23
  }
30
-
31
24
  /**
32
25
  * Send multisig exn request messages to other group members
33
26
  * @async
@@ -37,12 +30,7 @@ export class Groups {
37
30
  * @param {string} [atc] additional attachments from embedded events in exn
38
31
  * @returns {Promise<any>} A promise to the list of replay messages
39
32
  */
40
- async sendRequest(
41
- name: string,
42
- exn: Dict<any>,
43
- sigs: string[],
44
- atc: string
45
- ): Promise<any> {
33
+ async sendRequest(name, exn, sigs, atc) {
46
34
  const path = `/identifiers/${name}/multisig/request`;
47
35
  const method = 'POST';
48
36
  const data = {
@@ -53,7 +41,6 @@ export class Groups {
53
41
  const res = await this.client.fetch(path, method, data);
54
42
  return await res.json();
55
43
  }
56
-
57
44
  /**
58
45
  * Join multisig group using rotation event.
59
46
  * This can be used by participants being asked to contribute keys to a rotation event to join an existing group.
@@ -66,19 +53,13 @@ export class Groups {
66
53
  * @param {string[]} [rmids] array of particpants
67
54
  * @returns {Promise<any>} A promise to the list of replay messages
68
55
  */
69
- async join(
70
- name: string,
71
- rot: any,
72
- sigs: any, //string[],
73
- gid: string,
74
- smids: string[],
75
- rmids: string[]
76
- ): Promise<any> {
56
+ async join(name, rot, sigs, //string[],
57
+ gid, smids, rmids) {
77
58
  const path = `/identifiers/${name}/multisig/join`;
78
59
  const method = 'POST';
79
60
  const data = {
80
61
  tpc: 'multisig',
81
- rot: rot.ked,
62
+ rot: rot.sad,
82
63
  sigs: sigs,
83
64
  gid: gid,
84
65
  smids: smids,
@@ -1,5 +1,5 @@
1
- import { Manager } from '../core/manager';
2
- import { Serder } from '../core/serder';
1
+ import { Manager } from '../core/manager.ts';
2
+ import { Serder } from '../core/serder.ts';
3
3
  export declare class TraitCodex {
4
4
  EstOnly: string;
5
5
  DoNotDelegate: string;
@@ -0,0 +1,117 @@
1
+ import { Algos, Manager } from "../core/manager.js";
2
+ import { MtrDex } from "../core/matter.js";
3
+ import { Salter } from "../core/salter.js";
4
+ import { incept } from "../core/eventing.js";
5
+ export class TraitCodex {
6
+ constructor() {
7
+ this.EstOnly = 'EO'; // Only allow establishment events
8
+ this.DoNotDelegate = 'DND'; // Dot not allow delegated identifiers
9
+ this.NoBackers = 'NB'; // Do not allow backers
10
+ }
11
+ }
12
+ export const TraitDex = new TraitCodex();
13
+ export class Hab {
14
+ constructor(name, icp) {
15
+ this.name = name;
16
+ this.serder = icp;
17
+ }
18
+ get pre() {
19
+ return this.serder.sad['i'];
20
+ }
21
+ }
22
+ export class Habery {
23
+ constructor({ name, passcode, seed, aeid, pidx, salt }) {
24
+ this._habs = new Map();
25
+ this._name = name;
26
+ if (passcode != undefined && seed == undefined) {
27
+ if (passcode.length < 21) {
28
+ throw new Error('Bran (passcode seed material) too short.');
29
+ }
30
+ const bran = MtrDex.Salt_128 + 'A' + passcode.substring(0, 21); // qb64 salt for seed
31
+ const signer = new Salter({ qb64: bran }).signer(MtrDex.Ed25519_Seed, false);
32
+ seed = signer.qb64;
33
+ if (aeid == undefined) {
34
+ aeid = signer.verfer.qb64; // lest it remove encryption
35
+ }
36
+ }
37
+ let algo;
38
+ const salter = salt != undefined ? new Salter({ qb64: salt }) : undefined;
39
+ if (salt != undefined) {
40
+ algo = Algos.salty;
41
+ }
42
+ else {
43
+ algo = Algos.randy;
44
+ }
45
+ this._mgr = new Manager({
46
+ seed: seed,
47
+ aeid: aeid,
48
+ pidx: pidx,
49
+ algo: algo,
50
+ salter: salter,
51
+ });
52
+ }
53
+ get mgr() {
54
+ return this._mgr;
55
+ }
56
+ get habs() {
57
+ return Array.from(this._habs.values());
58
+ }
59
+ habByName(name) {
60
+ return this._habs.get(name);
61
+ }
62
+ makeHab(name, { code = MtrDex.Blake3_256, transferable = true, isith = undefined, icount = 1, nsith = undefined, ncount = undefined, toad = undefined, wits = undefined, delpre = undefined, estOnly = false, DnD = false, data = undefined, }) {
63
+ if (nsith == undefined) {
64
+ nsith = isith;
65
+ }
66
+ if (ncount == undefined) {
67
+ ncount = icount;
68
+ }
69
+ if (!transferable) {
70
+ ncount = 0;
71
+ nsith = '0';
72
+ code = MtrDex.Ed25519N;
73
+ }
74
+ const [verfers, digers] = this._mgr.incept({
75
+ icount: icount,
76
+ ncount: ncount,
77
+ stem: this.name,
78
+ transferable: transferable,
79
+ temp: false,
80
+ });
81
+ icount = verfers.length;
82
+ ncount = digers != undefined ? digers.length : 0;
83
+ if (isith == undefined) {
84
+ isith = `${Math.max(1, Math.ceil(icount / 2)).toString(16)}`;
85
+ }
86
+ if (nsith == undefined) {
87
+ nsith = `${Math.max(1, Math.ceil(ncount / 2)).toString(16)}`;
88
+ }
89
+ const cnfg = new Array();
90
+ if (estOnly) {
91
+ cnfg.push(TraitDex.EstOnly);
92
+ }
93
+ if (DnD) {
94
+ cnfg.push(TraitDex.DoNotDelegate);
95
+ }
96
+ const keys = Array.from(verfers, (verfer) => verfer.qb64);
97
+ const ndigs = Array.from(digers, (diger) => diger.qb64);
98
+ const icp = incept({
99
+ keys,
100
+ isith,
101
+ ndigs,
102
+ nsith,
103
+ toad,
104
+ wits,
105
+ cnfg,
106
+ data,
107
+ code,
108
+ delpre,
109
+ });
110
+ const hab = new Hab(name, icp);
111
+ this._habs.set(name, hab);
112
+ return hab;
113
+ }
114
+ get name() {
115
+ return this._name;
116
+ }
117
+ }
@@ -1,4 +1,4 @@
1
- import { SignifyClient } from './clienting';
1
+ import { SignifyClient } from './clienting.ts';
2
2
  /**
3
3
  * Notifications
4
4
  */
@@ -28,7 +28,7 @@ export declare class Notifications {
28
28
  * Delete a notification
29
29
  * @async
30
30
  * @param {string} said SAID of the notification
31
- * @returns {Promise<any>} A promise to the result of the deletion
31
+ * @returns {Promise<void>}
32
32
  */
33
33
  delete(said: string): Promise<void>;
34
34
  }
@@ -1,20 +1,15 @@
1
- import { SignifyClient } from './clienting';
2
- import { parseRangeHeaders } from '../core/httping';
3
-
1
+ import { parseRangeHeaders } from "../core/httping.js";
4
2
  /**
5
3
  * Notifications
6
4
  */
7
5
  export class Notifications {
8
- client: SignifyClient;
9
-
10
6
  /**
11
7
  * Notifications
12
8
  * @param {SignifyClient} client
13
9
  */
14
- constructor(client: SignifyClient) {
10
+ constructor(client) {
15
11
  this.client = client;
16
12
  }
17
-
18
13
  /**
19
14
  * List notifications
20
15
  * @async
@@ -22,18 +17,15 @@ export class Notifications {
22
17
  * @param {number} [end=24] End index of list of notifications, defaults to 24
23
18
  * @returns {Promise<any>} A promise to the list of notifications
24
19
  */
25
- async list(start: number = 0, end: number = 24): Promise<any> {
20
+ async list(start = 0, end = 24) {
26
21
  const extraHeaders = new Headers();
27
22
  extraHeaders.append('Range', `notes=${start}-${end}`);
28
-
29
23
  const path = `/notifications`;
30
24
  const method = 'GET';
31
25
  const res = await this.client.fetch(path, method, null, extraHeaders);
32
-
33
26
  const cr = res.headers.get('content-range');
34
27
  const range = parseRangeHeaders(cr, 'notes');
35
28
  const notes = await res.json();
36
-
37
29
  return {
38
30
  start: range.start,
39
31
  end: range.end,
@@ -41,29 +33,27 @@ export class Notifications {
41
33
  notes: notes,
42
34
  };
43
35
  }
44
-
45
36
  /**
46
37
  * Mark a notification as read
47
38
  * @async
48
39
  * @param {string} said SAID of the notification
49
40
  * @returns {Promise<string>} A promise to the result of the marking
50
41
  */
51
- async mark(said: string): Promise<string> {
42
+ async mark(said) {
52
43
  const path = `/notifications/` + said;
53
44
  const method = 'PUT';
54
45
  const res = await this.client.fetch(path, method, null);
55
46
  return await res.text();
56
47
  }
57
-
58
48
  /**
59
49
  * Delete a notification
60
50
  * @async
61
51
  * @param {string} said SAID of the notification
62
- * @returns {Promise<any>} A promise to the result of the deletion
52
+ * @returns {Promise<void>}
63
53
  */
64
- async delete(said: string): Promise<void> {
54
+ async delete(said) {
65
55
  const path = `/notifications/` + said;
66
56
  const method = 'DELETE';
67
- await this.client.fetch(path, method, null);
57
+ await this.client.fetch(path, method, undefined);
68
58
  }
69
59
  }
@@ -1,5 +1,5 @@
1
- import { Signer } from './signer';
2
- import { Verfer } from './verfer';
1
+ import { Signer } from './signer.ts';
2
+ import { Verfer } from './verfer.ts';
3
3
  export declare class Authenticater {
4
4
  static DefaultFields: string[];
5
5
  private _verfer;
@@ -1,26 +1,12 @@
1
- import { Signer } from './signer';
2
- import { Verfer } from './verfer';
3
- import { desiginput, normalize, siginput } from './httping';
4
- import { Signage, signature, designature } from '../end/ending';
5
- import { Cigar } from './cigar';
6
- import { Siger } from './siger';
1
+ import { desiginput, HEADER_SIG_INPUT, HEADER_SIG_TIME, normalize, siginput, } from "./httping.js";
2
+ import { Signage, signature, designature } from "../end/ending.js";
7
3
  export class Authenticater {
8
- static DefaultFields = [
9
- '@method',
10
- '@path',
11
- 'signify-resource',
12
- 'signify-timestamp',
13
- ];
14
- private _verfer: Verfer;
15
- private readonly _csig: Signer;
16
-
17
- constructor(csig: Signer, verfer: Verfer) {
4
+ constructor(csig, verfer) {
18
5
  this._csig = csig;
19
6
  this._verfer = verfer;
20
7
  }
21
-
22
- verify(headers: Headers, method: string, path: string): boolean {
23
- const siginput = headers.get('Signature-Input');
8
+ verify(headers, method, path) {
9
+ const siginput = headers.get(HEADER_SIG_INPUT);
24
10
  if (siginput == null) {
25
11
  return false;
26
12
  }
@@ -34,23 +20,25 @@ export class Authenticater {
34
20
  return false;
35
21
  }
36
22
  inputs.forEach((input) => {
37
- const items = new Array<string>();
38
- input.fields!.forEach((field: string) => {
23
+ const items = new Array();
24
+ input.fields.forEach((field) => {
39
25
  if (field.startsWith('@')) {
40
26
  if (field == '@method') {
41
27
  items.push(`"${field}": ${method}`);
42
- } else if (field == '@path') {
28
+ }
29
+ else if (field == '@path') {
43
30
  items.push(`"${field}": ${path}`);
44
31
  }
45
- } else {
32
+ }
33
+ else {
46
34
  if (headers.has(field)) {
47
- const value = normalize(headers.get(field) as string);
35
+ const value = normalize(headers.get(field));
48
36
  items.push(`"${field}": ${value}`);
49
37
  }
50
38
  }
51
39
  });
52
- const values = new Array<string>();
53
- values.push(`(${input.fields!.join(' ')})`);
40
+ const values = new Array();
41
+ values.push(`(${input.fields.join(' ')})`);
54
42
  values.push(`created=${input.created}`);
55
43
  if (input.expires != undefined) {
56
44
  values.push(`expires=${input.expires}`);
@@ -70,26 +58,19 @@ export class Authenticater {
70
58
  const params = values.join(';');
71
59
  items.push(`"@signature-params: ${params}"`);
72
60
  const ser = items.join('\n');
73
- const signage = designature(signature!);
74
- const cig = signage[0].markers.get(input.name);
75
- if (!this._verfer.verify(cig.raw, ser)) {
61
+ const signage = designature(signature);
62
+ const markers = signage[0].markers;
63
+ const cig = markers.get(input.name);
64
+ if (!cig || !this._verfer.verify(cig.raw, ser)) {
76
65
  throw new Error(`Signature for ${input.keyid} invalid.`);
77
66
  }
78
67
  });
79
-
80
68
  return true;
81
69
  }
82
-
83
- sign(
84
- headers: Headers,
85
- method: string,
86
- path: string,
87
- fields?: Array<string>
88
- ): Headers {
70
+ sign(headers, method, path, fields) {
89
71
  if (fields == undefined) {
90
72
  fields = Authenticater.DefaultFields;
91
73
  }
92
-
93
74
  const [header, sig] = siginput(this._csig, {
94
75
  name: 'signify',
95
76
  method,
@@ -99,19 +80,22 @@ export class Authenticater {
99
80
  alg: 'ed25519',
100
81
  keyid: this._csig.verfer.qb64,
101
82
  });
102
-
103
83
  header.forEach((value, key) => {
104
84
  headers.append(key, value);
105
85
  });
106
-
107
- const markers = new Map<string, Siger | Cigar>();
86
+ const markers = new Map();
108
87
  markers.set('signify', sig);
109
88
  const signage = new Signage(markers, false);
110
89
  const signed = signature([signage]);
111
90
  signed.forEach((value, key) => {
112
91
  headers.append(key, value);
113
92
  });
114
-
115
93
  return headers;
116
94
  }
117
95
  }
96
+ Authenticater.DefaultFields = [
97
+ '@method',
98
+ '@path',
99
+ 'signify-resource',
100
+ HEADER_SIG_TIME.toLowerCase(),
101
+ ];
@@ -0,0 +1,2 @@
1
+ export declare function encodeBase64Url(input: Uint8Array): string;
2
+ export declare function decodeBase64Url(input: string): Uint8Array;