signify-ts 0.1.1 → 0.2.1

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 (115) hide show
  1. package/README.md +96 -47
  2. package/dist/buffer-polyfill.d.ts +1 -0
  3. package/dist/exports.d.ts +40 -0
  4. package/dist/index.d.ts +4 -3
  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 +245 -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 -47
  15. package/dist/keri/app/notifying.d.ts +34 -0
  16. package/dist/keri/core/authing.d.ts +10 -9
  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 -53
  21. package/dist/keri/core/counter.d.ts +43 -43
  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 -21
  26. package/dist/keri/core/httping.d.ts +44 -34
  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 -172
  31. package/dist/keri/core/matter.d.ts +116 -69
  32. package/dist/keri/core/number.d.ts +7 -6
  33. package/dist/keri/core/pather.d.ts +7 -0
  34. package/dist/keri/core/prefixer.d.ts +15 -15
  35. package/dist/keri/core/saider.d.ts +23 -23
  36. package/dist/keri/core/salter.d.ts +23 -23
  37. package/dist/keri/core/seqner.d.ts +15 -0
  38. package/dist/keri/core/serder.d.ts +31 -23
  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 -14
  42. package/dist/keri/core/utils.d.ts +20 -15
  43. package/dist/keri/core/vdring.d.ts +16 -0
  44. package/dist/keri/core/verfer.d.ts +13 -12
  45. package/dist/keri/end/ending.d.ts +13 -13
  46. package/dist/math.d.ts +1 -0
  47. package/dist/ready.d.ts +1 -0
  48. package/dist/signify-ts.cjs +7842 -0
  49. package/dist/signify-ts.cjs.development.js +6369 -256
  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 +6205 -229
  55. package/dist/signify-ts.esm.js.map +1 -1
  56. package/dist/signify-ts.mjs +7818 -0
  57. package/dist/signify-ts.mjs.map +7 -0
  58. package/package.json +49 -49
  59. package/src/buffer-polyfill.ts +5 -0
  60. package/src/exports.ts +44 -0
  61. package/src/index.ts +4 -5
  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 +841 -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 +118 -85
  72. package/src/keri/app/notifying.ts +69 -0
  73. package/src/keri/core/authing.ts +73 -85
  74. package/src/keri/core/bexter.ts +138 -0
  75. package/src/keri/core/cigar.ts +10 -11
  76. package/src/keri/core/cipher.ts +23 -14
  77. package/src/keri/core/core.ts +223 -81
  78. package/src/keri/core/counter.ts +182 -116
  79. package/src/keri/core/decrypter.ts +48 -34
  80. package/src/keri/core/diger.ts +23 -22
  81. package/src/keri/core/encrypter.ts +37 -27
  82. package/src/keri/core/eventing.ts +468 -106
  83. package/src/keri/core/httping.ts +151 -105
  84. package/src/keri/core/indexer.ts +313 -211
  85. package/src/keri/core/keeping.ts +679 -3
  86. package/src/keri/core/kering.ts +4 -6
  87. package/src/keri/core/manager.ts +660 -499
  88. package/src/keri/core/matter.ts +382 -148
  89. package/src/keri/core/number.ts +56 -11
  90. package/src/keri/core/pather.ts +98 -0
  91. package/src/keri/core/prefixer.ts +122 -101
  92. package/src/keri/core/saider.ts +104 -76
  93. package/src/keri/core/salter.ts +71 -40
  94. package/src/keri/core/seqner.ts +46 -0
  95. package/src/keri/core/serder.ts +102 -38
  96. package/src/keri/core/siger.ts +19 -18
  97. package/src/keri/core/signer.ts +73 -53
  98. package/src/keri/core/tholder.ts +196 -30
  99. package/src/keri/core/utils.ts +121 -50
  100. package/src/keri/core/vdring.ts +94 -0
  101. package/src/keri/core/verfer.ts +22 -9
  102. package/src/keri/end/ending.ts +111 -101
  103. package/src/math.ts +3 -0
  104. package/src/ready.ts +5 -0
  105. package/dist/keri/app/accountant.d.ts +0 -10
  106. package/dist/keri/app/apping.d.ts +0 -1
  107. package/dist/keri/app/client.d.ts +0 -7
  108. package/dist/keri/app/signify.d.ts +0 -6
  109. package/src/keri/app/accountant.ts +0 -35
  110. package/src/keri/app/apping.ts +0 -12
  111. package/src/keri/app/client.ts +0 -30
  112. package/src/keri/app/signify.ts +0 -12
  113. package/src/keri/app/tsconfig.json +0 -100
  114. package/src/keri/core/tsconfig.json +0 -100
  115. package/src/keri/end/tsconfig.json +0 -100
@@ -1,163 +1,209 @@
1
- import {serializeDictionary, Dictionary, parseDictionary, Item, Parameters} from "structured-headers";
2
- import {Signer} from "./signer";
3
- import {b} from "./core";
4
- import {Cigar} from "./cigar";
5
- import {nowUTC} from "./utils";
6
- import {Siger} from "./siger";
7
- import Base64 from "urlsafe-base64"
1
+ import {
2
+ serializeDictionary,
3
+ Dictionary,
4
+ parseDictionary,
5
+ Item,
6
+ Parameters,
7
+ } from 'structured-headers';
8
+ import { Signer } from './signer';
9
+ import { b } from './core';
10
+ import { Cigar } from './cigar';
11
+ import { nowUTC } from './utils';
12
+ import { Siger } from './siger';
13
+ import Base64 from 'urlsafe-base64';
8
14
  import { Buffer } from 'buffer';
9
15
 
10
16
  export function normalize(header: string) {
11
- return header.trim()
17
+ return header.trim();
12
18
  }
13
19
 
14
20
  export interface SiginputArgs {
15
- name: string,
16
- method:string,
17
- path:string,
18
- headers: Headers,
19
- fields: Array<string>,
20
- expires?:number,
21
- nonce?: string,
22
- alg?: string,
23
- keyid?: string,
24
- context?: string
21
+ name: string;
22
+ method: string;
23
+ path: string;
24
+ headers: Headers;
25
+ fields: Array<string>;
26
+ expires?: number;
27
+ nonce?: string;
28
+ alg?: string;
29
+ keyid?: string;
30
+ context?: string;
25
31
  }
26
32
 
27
- export function siginput(signer: Signer,
28
- {name, method, path, headers, fields,
29
- expires, nonce, alg, keyid, context}: SiginputArgs): [Map<string, string>, Siger|Cigar] {
30
-
31
- let items = new Array<string>()
32
- let ifields = new Array<[string, Map<string, string>]>()
33
+ export function siginput(
34
+ signer: Signer,
35
+ {
36
+ name,
37
+ method,
38
+ path,
39
+ headers,
40
+ fields,
41
+ expires,
42
+ nonce,
43
+ alg,
44
+ keyid,
45
+ context,
46
+ }: SiginputArgs
47
+ ): [Map<string, string>, Siger | Cigar] {
48
+ const items = new Array<string>();
49
+ const ifields = new Array<[string, Map<string, string>]>();
33
50
 
34
51
  fields.forEach((field) => {
35
- if (field.startsWith("@")) {
52
+ if (field.startsWith('@')) {
36
53
  switch (field) {
37
- case "@method":
38
- items.push(`"${field}": ${method}`)
39
- ifields.push([field, new Map()])
40
- break
41
- case "@path":
42
- items.push(`"${field}": ${path}`)
43
- ifields.push([field, new Map()])
44
- break
54
+ case '@method':
55
+ items.push(`"${field}": ${method}`);
56
+ ifields.push([field, new Map()]);
57
+ break;
58
+ case '@path':
59
+ items.push(`"${field}": ${path}`);
60
+ ifields.push([field, new Map()]);
61
+ break;
45
62
  }
46
63
  } else {
47
- if (!headers.has(field))
48
- return
64
+ if (!headers.has(field)) return;
49
65
 
50
- ifields.push([field, new Map()])
51
- let value = normalize(headers.get(field)!)
52
- items.push(`"${field}": ${value}`)
66
+ ifields.push([field, new Map()]);
67
+ const value = normalize(headers.get(field)!);
68
+ items.push(`"${field}": ${value}`);
53
69
  }
54
- })
70
+ });
55
71
 
56
- let nameParams = new Map<string, string|number>()
57
- let now = Math.floor(nowUTC().getTime() / 1000)
58
- nameParams.set("created", now)
72
+ const nameParams = new Map<string, string | number>();
73
+ const now = Math.floor(nowUTC().getTime() / 1000);
74
+ nameParams.set('created', now);
59
75
 
60
- let values = [`(${ifields.join(" ")})`, `created=${now}`]
76
+ const values = [
77
+ `(${ifields.map((field) => field[0]).join(' ')})`,
78
+ `created=${now}`,
79
+ ];
61
80
  if (expires != undefined) {
62
- values.push(`expires=${expires}`)
63
- nameParams.set('expires', expires)
81
+ values.push(`expires=${expires}`);
82
+ nameParams.set('expires', expires);
64
83
  }
65
84
  if (nonce != undefined) {
66
- values.push(`nonce=${nonce}`)
67
- nameParams.set('nonce', nonce)
85
+ values.push(`nonce=${nonce}`);
86
+ nameParams.set('nonce', nonce);
68
87
  }
69
88
  if (keyid != undefined) {
70
- values.push(`keyid=${keyid}`)
71
- nameParams.set('keyid', keyid)
89
+ values.push(`keyid=${keyid}`);
90
+ nameParams.set('keyid', keyid);
72
91
  }
73
92
  if (context != undefined) {
74
- values.push(`context=${context}`)
75
- nameParams.set('context', context)
93
+ values.push(`context=${context}`);
94
+ nameParams.set('context', context);
76
95
  }
77
96
  if (alg != undefined) {
78
- values.push(`alg=${alg}`)
79
- nameParams.set('alg', alg)
97
+ values.push(`alg=${alg}`);
98
+ nameParams.set('alg', alg);
80
99
  }
81
- let sid = new Map([
82
- [name, [ifields, nameParams]]
83
- ])
100
+ const sid = new Map([[name, [ifields, nameParams]]]);
84
101
 
85
- let params = values.join(";")
86
- items.push(`"@signature-params: ${params}"`)
102
+ const params = values.join(';');
103
+ items.push(`"@signature-params: ${params}"`);
87
104
 
88
- let ser = items.join("\n")
89
- let sig = signer.sign(b(ser))
105
+ const ser = items.join('\n');
106
+ const sig = signer.sign(b(ser));
90
107
 
91
- return [new Map<string, string>([['Signature-Input', `${serializeDictionary(sid as Dictionary)}`]]), sig]
108
+ return [
109
+ new Map<string, string>([
110
+ ['Signature-Input', `${serializeDictionary(sid as Dictionary)}`],
111
+ ]),
112
+ sig,
113
+ ];
92
114
  }
93
115
 
94
116
  export class Unqualified {
95
- private readonly _raw: Uint8Array
117
+ private readonly _raw: Uint8Array;
96
118
 
97
119
  constructor(raw: Uint8Array) {
98
- this._raw = raw
120
+ this._raw = raw;
99
121
  }
100
122
 
101
123
  get qb64(): string {
102
- return Base64.encode(Buffer.from(this._raw))
124
+ return Base64.encode(Buffer.from(this._raw));
103
125
  }
104
126
 
105
127
  get qb64b(): Uint8Array {
106
- return b(this.qb64)
128
+ return b(this.qb64);
107
129
  }
108
130
  }
109
131
 
110
132
  export class Inputage {
111
- public name: any
112
- public fields: any
113
- public created: any
114
- public expires: any
115
- public nonce: any
116
- public alg: any
117
- public keyid: any
118
- public context: any
133
+ public name: any;
134
+ public fields: any;
135
+ public created: any;
136
+ public expires: any;
137
+ public nonce: any;
138
+ public alg: any;
139
+ public keyid: any;
140
+ public context: any;
119
141
  }
120
142
 
121
143
  export function desiginput(value: string): Array<Inputage> {
122
- let sid = parseDictionary(value)
123
- let siginputs = new Array<Inputage>()
144
+ const sid = parseDictionary(value);
145
+ const siginputs = new Array<Inputage>();
124
146
 
125
147
  sid.forEach((value, key) => {
126
- let siginput = new Inputage()
127
- siginput.name = key
128
- let list: Item[]
129
- let params
130
- [list, params] = value as [Item[], Parameters]
131
- siginput.fields = list.map((item) => item[0])
132
-
133
- if (!params.has("created")) {
134
- throw new Error("missing required `created` field from signature input")
148
+ const siginput = new Inputage();
149
+ siginput.name = key;
150
+ let list: Item[];
151
+ let params;
152
+ [list, params] = value as [Item[], Parameters];
153
+ siginput.fields = list.map((item) => item[0]);
154
+
155
+ if (!params.has('created')) {
156
+ throw new Error(
157
+ 'missing required `created` field from signature input'
158
+ );
135
159
  }
136
- siginput.created = params.get("created")
137
-
138
- if (params.has("expires")) {
139
- siginput.expires = params.get("expires")
160
+ siginput.created = params.get('created');
161
+
162
+ if (params.has('expires')) {
163
+ siginput.expires = params.get('expires');
140
164
  }
141
-
142
- if (params.has("nonce")) {
143
- siginput.nonce = params.get("nonce")
165
+
166
+ if (params.has('nonce')) {
167
+ siginput.nonce = params.get('nonce');
144
168
  }
145
-
146
- if (params.has("alg")) {
147
- siginput.alg = params.get("alg")
169
+
170
+ if (params.has('alg')) {
171
+ siginput.alg = params.get('alg');
148
172
  }
149
-
150
- if (params.has("keyid")) {
151
- siginput.keyid = params.get("keyid")
173
+
174
+ if (params.has('keyid')) {
175
+ siginput.keyid = params.get('keyid');
152
176
  }
153
-
154
- if (params.has("context")) {
155
- siginput.context = params.get("context")
177
+
178
+ if (params.has('context')) {
179
+ siginput.context = params.get('context');
156
180
  }
157
-
158
- siginputs.push(siginput)
159
- })
160
181
 
161
- return siginputs
182
+ siginputs.push(siginput);
183
+ });
162
184
 
163
- }
185
+ return siginputs;
186
+ }
187
+ /** Parse start, end and total from HTTP Content-Range header value
188
+ * @param {string|null} header - HTTP Range header value
189
+ * @param {string} typ - type of range, e.g. "aids"
190
+ * @returns {start: number, end: number, total: number} - object with start, end and total properties
191
+ */
192
+ export function parseRangeHeaders(
193
+ header: string | null,
194
+ typ: string
195
+ ): { start: number; end: number; total: number } {
196
+ if (header !== null) {
197
+ const data = header.replace(`${typ} `, '');
198
+ const values = data.split('/');
199
+ const rng = values[0].split('-');
200
+
201
+ return {
202
+ start: parseInt(rng[0]),
203
+ end: parseInt(rng[1]),
204
+ total: parseInt(values[1]),
205
+ };
206
+ } else {
207
+ return { start: 0, end: 0, total: 0 };
208
+ }
209
+ }