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
@@ -0,0 +1,209 @@
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';
14
+ import { Buffer } from 'buffer';
15
+
16
+ export function normalize(header: string) {
17
+ return header.trim();
18
+ }
19
+
20
+ export interface SiginputArgs {
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;
31
+ }
32
+
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>]>();
50
+
51
+ fields.forEach((field) => {
52
+ if (field.startsWith('@')) {
53
+ switch (field) {
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;
62
+ }
63
+ } else {
64
+ if (!headers.has(field)) return;
65
+
66
+ ifields.push([field, new Map()]);
67
+ const value = normalize(headers.get(field)!);
68
+ items.push(`"${field}": ${value}`);
69
+ }
70
+ });
71
+
72
+ const nameParams = new Map<string, string | number>();
73
+ const now = Math.floor(nowUTC().getTime() / 1000);
74
+ nameParams.set('created', now);
75
+
76
+ const values = [
77
+ `(${ifields.map((field) => field[0]).join(' ')})`,
78
+ `created=${now}`,
79
+ ];
80
+ if (expires != undefined) {
81
+ values.push(`expires=${expires}`);
82
+ nameParams.set('expires', expires);
83
+ }
84
+ if (nonce != undefined) {
85
+ values.push(`nonce=${nonce}`);
86
+ nameParams.set('nonce', nonce);
87
+ }
88
+ if (keyid != undefined) {
89
+ values.push(`keyid=${keyid}`);
90
+ nameParams.set('keyid', keyid);
91
+ }
92
+ if (context != undefined) {
93
+ values.push(`context=${context}`);
94
+ nameParams.set('context', context);
95
+ }
96
+ if (alg != undefined) {
97
+ values.push(`alg=${alg}`);
98
+ nameParams.set('alg', alg);
99
+ }
100
+ const sid = new Map([[name, [ifields, nameParams]]]);
101
+
102
+ const params = values.join(';');
103
+ items.push(`"@signature-params: ${params}"`);
104
+
105
+ const ser = items.join('\n');
106
+ const sig = signer.sign(b(ser));
107
+
108
+ return [
109
+ new Map<string, string>([
110
+ ['Signature-Input', `${serializeDictionary(sid as Dictionary)}`],
111
+ ]),
112
+ sig,
113
+ ];
114
+ }
115
+
116
+ export class Unqualified {
117
+ private readonly _raw: Uint8Array;
118
+
119
+ constructor(raw: Uint8Array) {
120
+ this._raw = raw;
121
+ }
122
+
123
+ get qb64(): string {
124
+ return Base64.encode(Buffer.from(this._raw));
125
+ }
126
+
127
+ get qb64b(): Uint8Array {
128
+ return b(this.qb64);
129
+ }
130
+ }
131
+
132
+ export class Inputage {
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;
141
+ }
142
+
143
+ export function desiginput(value: string): Array<Inputage> {
144
+ const sid = parseDictionary(value);
145
+ const siginputs = new Array<Inputage>();
146
+
147
+ sid.forEach((value, key) => {
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
+ );
159
+ }
160
+ siginput.created = params.get('created');
161
+
162
+ if (params.has('expires')) {
163
+ siginput.expires = params.get('expires');
164
+ }
165
+
166
+ if (params.has('nonce')) {
167
+ siginput.nonce = params.get('nonce');
168
+ }
169
+
170
+ if (params.has('alg')) {
171
+ siginput.alg = params.get('alg');
172
+ }
173
+
174
+ if (params.has('keyid')) {
175
+ siginput.keyid = params.get('keyid');
176
+ }
177
+
178
+ if (params.has('context')) {
179
+ siginput.context = params.get('context');
180
+ }
181
+
182
+ siginputs.push(siginput);
183
+ });
184
+
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
+ }