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.
- package/README.md +104 -34
- package/dist/exports.d.ts +40 -40
- package/dist/exports.js +40 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +3 -8
- package/dist/keri/app/aiding.d.ts +34 -14
- package/{src/keri/app/aiding.ts → dist/keri/app/aiding.js} +104 -235
- package/dist/keri/app/clienting.d.ts +57 -22
- package/{src/keri/app/clienting.ts → dist/keri/app/clienting.js} +145 -234
- package/dist/keri/app/contacting.d.ts +33 -21
- package/{src/keri/app/contacting.ts → dist/keri/app/contacting.js} +25 -62
- package/dist/keri/app/controller.d.ts +49 -6
- package/{src/keri/app/controller.ts → dist/keri/app/controller.js} +79 -185
- package/dist/keri/app/coring.d.ts +30 -8
- package/{src/keri/app/coring.ts → dist/keri/app/coring.js} +62 -51
- package/dist/keri/app/credentialing.d.ts +183 -65
- package/dist/keri/app/credentialing.js +540 -0
- package/dist/keri/app/delegating.d.ts +18 -0
- package/dist/keri/app/delegating.js +24 -0
- package/dist/keri/app/escrowing.d.ts +1 -1
- package/{src/keri/app/escrowing.ts → dist/keri/app/escrowing.js} +2 -8
- package/dist/keri/app/exchanging.d.ts +7 -6
- package/{src/keri/app/exchanging.ts → dist/keri/app/exchanging.js} +33 -110
- package/dist/keri/app/grouping.d.ts +2 -2
- package/{src/keri/app/grouping.ts → dist/keri/app/grouping.js} +6 -25
- package/dist/keri/app/habery.d.ts +2 -2
- package/dist/keri/app/habery.js +117 -0
- package/dist/keri/app/notifying.d.ts +2 -2
- package/{src/keri/app/notifying.ts → dist/keri/app/notifying.js} +7 -17
- package/dist/keri/core/authing.d.ts +2 -2
- package/{src/keri/core/authing.ts → dist/keri/core/authing.js} +26 -42
- package/dist/keri/core/base64.d.ts +2 -0
- package/dist/keri/core/base64.js +16 -0
- package/dist/keri/core/bexter.d.ts +1 -1
- package/{src/keri/core/bexter.ts → dist/keri/core/bexter.js} +18 -32
- package/dist/keri/core/cigar.d.ts +2 -2
- package/dist/keri/core/cigar.js +13 -0
- package/dist/keri/core/cipher.d.ts +1 -1
- package/{src/keri/core/cipher.ts → dist/keri/core/cipher.js} +10 -19
- package/dist/keri/core/core.d.ts +117 -9
- package/dist/keri/core/core.js +385 -0
- package/dist/keri/core/counter.d.ts +2 -2
- package/dist/keri/core/counter.js +221 -0
- package/dist/keri/core/decrypter.d.ts +4 -4
- package/{src/keri/core/decrypter.ts → dist/keri/core/decrypter.js} +23 -40
- package/dist/keri/core/diger.d.ts +3 -3
- package/{src/keri/core/diger.ts → dist/keri/core/diger.js} +18 -33
- package/dist/keri/core/encrypter.d.ts +2 -2
- package/{src/keri/core/encrypter.ts → dist/keri/core/encrypter.js} +18 -38
- package/dist/keri/core/eventing.d.ts +4 -4
- package/{src/keri/core/eventing.ts → dist/keri/core/eventing.js} +134 -321
- package/dist/keri/core/httping.d.ts +11 -4
- package/{src/keri/core/httping.ts → dist/keri/core/httping.js} +36 -101
- package/dist/keri/core/indexer.d.ts +1 -1
- package/dist/keri/core/indexer.js +407 -0
- package/dist/keri/core/keeping.d.ts +98 -46
- package/dist/keri/core/keeping.js +365 -0
- package/{src/keri/core/kering.ts → dist/keri/core/kering.js} +1 -3
- package/dist/keri/core/keyState.d.ts +85 -0
- package/dist/keri/core/keyState.js +1 -0
- package/dist/keri/core/manager.d.ts +147 -12
- package/dist/keri/core/manager.js +880 -0
- package/dist/keri/core/matter.d.ts +1 -1
- package/dist/keri/core/matter.js +460 -0
- package/dist/keri/core/number.d.ts +1 -1
- package/{src/keri/core/number.ts → dist/keri/core/number.js} +21 -30
- package/dist/keri/core/pather.d.ts +2 -2
- package/{src/keri/core/pather.ts → dist/keri/core/pather.js} +12 -27
- package/dist/keri/core/prefixer.d.ts +10 -10
- package/dist/keri/core/prefixer.js +182 -0
- package/dist/keri/core/saider.d.ts +2 -12
- package/dist/keri/core/saider.js +107 -0
- package/dist/keri/core/salter.d.ts +45 -3
- package/dist/keri/core/salter.js +117 -0
- package/dist/keri/core/seqner.d.ts +1 -1
- package/{src/keri/core/seqner.ts → dist/keri/core/seqner.js} +20 -21
- package/dist/keri/core/serder.d.ts +25 -12
- package/dist/keri/core/serder.js +133 -0
- package/dist/keri/core/siger.d.ts +2 -2
- package/{src/keri/core/siger.ts → dist/keri/core/siger.js} +4 -14
- package/dist/keri/core/signer.d.ts +4 -4
- package/dist/keri/core/signer.js +84 -0
- package/{src/keri/core/tholder.ts → dist/keri/core/tholder.js} +69 -94
- package/dist/keri/core/utils.d.ts +1 -1
- package/{src/keri/core/utils.ts → dist/keri/core/utils.js} +30 -60
- package/dist/keri/core/vdring.d.ts +2 -2
- package/dist/keri/core/vdring.js +61 -0
- package/dist/keri/core/verfer.d.ts +2 -6
- package/dist/keri/core/verfer.js +37 -0
- package/dist/keri/end/ending.d.ts +10 -8
- package/dist/keri/end/ending.js +136 -0
- package/{src/ready.ts → dist/ready.js} +1 -2
- package/dist/types/keria-api-schema.d.ts +304 -0
- package/dist/types/keria-api-schema.js +2 -0
- package/package.json +53 -50
- package/dist/buffer-polyfill.d.ts +0 -1
- package/dist/math.d.ts +0 -1
- package/dist/signify-ts.cjs +0 -7842
- package/dist/signify-ts.cjs.development.js +0 -9501
- package/dist/signify-ts.cjs.development.js.map +0 -1
- package/dist/signify-ts.cjs.map +0 -7
- package/dist/signify-ts.cjs.production.min.js +0 -2
- package/dist/signify-ts.cjs.production.min.js.map +0 -1
- package/dist/signify-ts.esm.js +0 -9345
- package/dist/signify-ts.esm.js.map +0 -1
- package/dist/signify-ts.mjs +0 -7818
- package/dist/signify-ts.mjs.map +0 -7
- package/src/buffer-polyfill.ts +0 -5
- package/src/exports.ts +0 -44
- package/src/index.ts +0 -4
- package/src/keri/app/credentialing.ts +0 -841
- package/src/keri/app/habery.ts +0 -185
- package/src/keri/core/cigar.ts +0 -18
- package/src/keri/core/core.ts +0 -326
- package/src/keri/core/counter.ts +0 -273
- package/src/keri/core/indexer.ts +0 -509
- package/src/keri/core/keeping.ts +0 -684
- package/src/keri/core/manager.ts +0 -1183
- package/src/keri/core/matter.ts +0 -521
- package/src/keri/core/prefixer.ts +0 -233
- package/src/keri/core/saider.ts +0 -186
- package/src/keri/core/salter.ts +0 -120
- package/src/keri/core/serder.ts +0 -163
- package/src/keri/core/signer.ts +0 -133
- package/src/keri/core/vdring.ts +0 -94
- package/src/keri/core/verfer.ts +0 -47
- package/src/keri/end/ending.ts +0 -170
- package/src/math.ts +0 -3
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { Signer } from './signer';
|
|
2
|
-
import { Cigar } from './cigar';
|
|
3
|
-
import { Siger } from './siger';
|
|
1
|
+
import { Signer } from './signer.ts';
|
|
2
|
+
import { Cigar } from './cigar.ts';
|
|
3
|
+
import { Siger } from './siger.ts';
|
|
4
|
+
export declare const HEADER_SIG_INPUT: string;
|
|
5
|
+
export declare const HEADER_SIG_TIME: string;
|
|
4
6
|
export declare function normalize(header: string): string;
|
|
5
7
|
export interface SiginputArgs {
|
|
6
8
|
name: string;
|
|
@@ -14,7 +16,12 @@ export interface SiginputArgs {
|
|
|
14
16
|
keyid?: string;
|
|
15
17
|
context?: string;
|
|
16
18
|
}
|
|
17
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Generates, serializes, and signs a Signature-Input HTTP header value as a structured header
|
|
21
|
+
* @param signer
|
|
22
|
+
* @param sigInputArgs
|
|
23
|
+
*/
|
|
24
|
+
export declare function siginput(signer: Signer, sigInputArgs: SiginputArgs): [Map<string, string>, Siger | Cigar];
|
|
18
25
|
export declare class Unqualified {
|
|
19
26
|
private readonly _raw;
|
|
20
27
|
constructor(raw: Uint8Array);
|
|
@@ -1,53 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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) {
|
|
1
|
+
import { serializeDictionary, parseDictionary, } from 'structured-headers';
|
|
2
|
+
import { b } from "./core.js";
|
|
3
|
+
import { nowUTC } from "./utils.js";
|
|
4
|
+
import { encodeBase64Url } from "./base64.js";
|
|
5
|
+
export const HEADER_SIG_INPUT = normalize('Signature-Input');
|
|
6
|
+
export const HEADER_SIG_TIME = normalize('Signify-Timestamp');
|
|
7
|
+
export function normalize(header) {
|
|
17
8
|
return header.trim();
|
|
18
9
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
fields
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Generates, serializes, and signs a Signature-Input HTTP header value as a structured header
|
|
12
|
+
* @param signer
|
|
13
|
+
* @param sigInputArgs
|
|
14
|
+
*/
|
|
15
|
+
export function siginput(signer, sigInputArgs) {
|
|
16
|
+
const { name, method, path, headers, fields, expires, nonce, alg, keyid, context, } = sigInputArgs;
|
|
17
|
+
const items = new Array();
|
|
18
|
+
const ifields = new Array();
|
|
51
19
|
fields.forEach((field) => {
|
|
52
20
|
if (field.startsWith('@')) {
|
|
53
21
|
switch (field) {
|
|
@@ -60,19 +28,18 @@ export function siginput(
|
|
|
60
28
|
ifields.push([field, new Map()]);
|
|
61
29
|
break;
|
|
62
30
|
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
if (!headers.has(field))
|
|
34
|
+
return;
|
|
66
35
|
ifields.push([field, new Map()]);
|
|
67
|
-
const value = normalize(headers.get(field)
|
|
36
|
+
const value = normalize(headers.get(field));
|
|
68
37
|
items.push(`"${field}": ${value}`);
|
|
69
38
|
}
|
|
70
39
|
});
|
|
71
|
-
|
|
72
|
-
const nameParams = new Map<string, string | number>();
|
|
40
|
+
const nameParams = new Map();
|
|
73
41
|
const now = Math.floor(nowUTC().getTime() / 1000);
|
|
74
42
|
nameParams.set('created', now);
|
|
75
|
-
|
|
76
43
|
const values = [
|
|
77
44
|
`(${ifields.map((field) => field[0]).join(' ')})`,
|
|
78
45
|
`created=${now}`,
|
|
@@ -98,90 +65,61 @@ export function siginput(
|
|
|
98
65
|
nameParams.set('alg', alg);
|
|
99
66
|
}
|
|
100
67
|
const sid = new Map([[name, [ifields, nameParams]]]);
|
|
101
|
-
|
|
102
68
|
const params = values.join(';');
|
|
103
69
|
items.push(`"@signature-params: ${params}"`);
|
|
104
|
-
|
|
105
70
|
const ser = items.join('\n');
|
|
106
71
|
const sig = signer.sign(b(ser));
|
|
107
|
-
|
|
108
72
|
return [
|
|
109
|
-
new Map
|
|
110
|
-
[
|
|
73
|
+
new Map([
|
|
74
|
+
[HEADER_SIG_INPUT, `${serializeDictionary(sid)}`],
|
|
111
75
|
]),
|
|
112
76
|
sig,
|
|
113
77
|
];
|
|
114
78
|
}
|
|
115
|
-
|
|
116
79
|
export class Unqualified {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
constructor(raw: Uint8Array) {
|
|
80
|
+
constructor(raw) {
|
|
120
81
|
this._raw = raw;
|
|
121
82
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return Base64.encode(Buffer.from(this._raw));
|
|
83
|
+
get qb64() {
|
|
84
|
+
return encodeBase64Url(this._raw);
|
|
125
85
|
}
|
|
126
|
-
|
|
127
|
-
get qb64b(): Uint8Array {
|
|
86
|
+
get qb64b() {
|
|
128
87
|
return b(this.qb64);
|
|
129
88
|
}
|
|
130
89
|
}
|
|
131
|
-
|
|
132
90
|
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
91
|
}
|
|
142
|
-
|
|
143
|
-
export function desiginput(value: string): Array<Inputage> {
|
|
92
|
+
export function desiginput(value) {
|
|
144
93
|
const sid = parseDictionary(value);
|
|
145
|
-
const siginputs = new Array
|
|
146
|
-
|
|
94
|
+
const siginputs = new Array();
|
|
147
95
|
sid.forEach((value, key) => {
|
|
148
96
|
const siginput = new Inputage();
|
|
149
97
|
siginput.name = key;
|
|
150
|
-
let list
|
|
98
|
+
let list;
|
|
151
99
|
let params;
|
|
152
|
-
[list, params] = value
|
|
100
|
+
[list, params] = value;
|
|
153
101
|
siginput.fields = list.map((item) => item[0]);
|
|
154
|
-
|
|
155
102
|
if (!params.has('created')) {
|
|
156
|
-
throw new Error(
|
|
157
|
-
'missing required `created` field from signature input'
|
|
158
|
-
);
|
|
103
|
+
throw new Error('missing required `created` field from signature input');
|
|
159
104
|
}
|
|
160
105
|
siginput.created = params.get('created');
|
|
161
|
-
|
|
162
106
|
if (params.has('expires')) {
|
|
163
107
|
siginput.expires = params.get('expires');
|
|
164
108
|
}
|
|
165
|
-
|
|
166
109
|
if (params.has('nonce')) {
|
|
167
110
|
siginput.nonce = params.get('nonce');
|
|
168
111
|
}
|
|
169
|
-
|
|
170
112
|
if (params.has('alg')) {
|
|
171
113
|
siginput.alg = params.get('alg');
|
|
172
114
|
}
|
|
173
|
-
|
|
174
115
|
if (params.has('keyid')) {
|
|
175
116
|
siginput.keyid = params.get('keyid');
|
|
176
117
|
}
|
|
177
|
-
|
|
178
118
|
if (params.has('context')) {
|
|
179
119
|
siginput.context = params.get('context');
|
|
180
120
|
}
|
|
181
|
-
|
|
182
121
|
siginputs.push(siginput);
|
|
183
122
|
});
|
|
184
|
-
|
|
185
123
|
return siginputs;
|
|
186
124
|
}
|
|
187
125
|
/** Parse start, end and total from HTTP Content-Range header value
|
|
@@ -189,21 +127,18 @@ export function desiginput(value: string): Array<Inputage> {
|
|
|
189
127
|
* @param {string} typ - type of range, e.g. "aids"
|
|
190
128
|
* @returns {start: number, end: number, total: number} - object with start, end and total properties
|
|
191
129
|
*/
|
|
192
|
-
export function parseRangeHeaders(
|
|
193
|
-
header: string | null,
|
|
194
|
-
typ: string
|
|
195
|
-
): { start: number; end: number; total: number } {
|
|
130
|
+
export function parseRangeHeaders(header, typ) {
|
|
196
131
|
if (header !== null) {
|
|
197
132
|
const data = header.replace(`${typ} `, '');
|
|
198
133
|
const values = data.split('/');
|
|
199
134
|
const rng = values[0].split('-');
|
|
200
|
-
|
|
201
135
|
return {
|
|
202
136
|
start: parseInt(rng[0]),
|
|
203
137
|
end: parseInt(rng[1]),
|
|
204
138
|
total: parseInt(values[1]),
|
|
205
139
|
};
|
|
206
|
-
}
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
207
142
|
return { start: 0, end: 0, total: 0 };
|
|
208
143
|
}
|
|
209
144
|
}
|
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
import { EmptyMaterialError } from "./kering.js";
|
|
2
|
+
import { b, b64ToInt, d, intToB64, readInt } from "./core.js";
|
|
3
|
+
import { decodeBase64Url, encodeBase64Url } from "./base64.js";
|
|
4
|
+
export class IndexerCodex {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.Ed25519_Sig = 'A'; // Ed25519 sig appears same in both lists if any.
|
|
7
|
+
this.Ed25519_Crt_Sig = 'B'; // Ed25519 sig appears in current list only.
|
|
8
|
+
this.ECDSA_256k1_Sig = 'C'; // ECDSA secp256k1 sig appears same in both lists if any.
|
|
9
|
+
this.ECDSA_256k1_Crt_Sig = 'D'; // ECDSA secp256k1 sig appears in current list.
|
|
10
|
+
this.ECDSA_256r1_Sig = 'E'; // ECDSA secp256r1 sig appears same in both lists if any.
|
|
11
|
+
this.ECDSA_256r1_Crt_Sig = 'F'; // ECDSA secp256r1 sig appears in current list.
|
|
12
|
+
this.Ed448_Sig = '0A'; // Ed448 signature appears in both lists.
|
|
13
|
+
this.Ed448_Crt_Sig = '0B'; // Ed448 signature appears in current list only.
|
|
14
|
+
this.Ed25519_Big_Sig = '2A'; // Ed25519 sig appears in both lists.
|
|
15
|
+
this.Ed25519_Big_Crt_Sig = '2B'; // Ed25519 sig appears in current list only.
|
|
16
|
+
this.ECDSA_256k1_Big_Sig = '2C'; // ECDSA secp256k1 sig appears in both lists.
|
|
17
|
+
this.ECDSA_256k1_Big_Crt_Sig = '2D'; // ECDSA secp256k1 sig appears in current list only.
|
|
18
|
+
this.ECDSA_256r1_Big_Sig = '2E'; // ECDSA secp256r1 sig appears in both lists.
|
|
19
|
+
this.ECDSA_256r1_Big_Crt_Sig = '2F'; // ECDSA secp256r1 sig appears in current list only.
|
|
20
|
+
this.Ed448_Big_Sig = '3A'; // Ed448 signature appears in both lists.
|
|
21
|
+
this.Ed448_Big_Crt_Sig = '3B'; // Ed448 signature appears in current list only.
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export const IdrDex = new IndexerCodex();
|
|
25
|
+
export class IndexedSigCodex {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.Ed25519_Sig = 'A'; // Ed25519 sig appears same in both lists if any.
|
|
28
|
+
this.Ed25519_Crt_Sig = 'B'; // Ed25519 sig appears in current list only.
|
|
29
|
+
this.ECDSA_256k1_Sig = 'C'; // ECDSA secp256k1 sig appears same in both lists if any.
|
|
30
|
+
this.ECDSA_256k1_Crt_Sig = 'D'; // ECDSA secp256k1 sig appears in current list.
|
|
31
|
+
this.ECDSA_256r1_Sig = 'E'; // ECDSA secp256r1 sig appears same in both lists if any.
|
|
32
|
+
this.ECDSA_256r1_Crt_Sig = 'F'; // ECDSA secp256r1 sig appears in current list.
|
|
33
|
+
this.Ed448_Sig = '0A'; // Ed448 signature appears in both lists.
|
|
34
|
+
this.Ed448_Crt_Sig = '0B'; // Ed448 signature appears in current list only.
|
|
35
|
+
this.Ed25519_Big_Sig = '2A'; // Ed25519 sig appears in both lists.
|
|
36
|
+
this.Ed25519_Big_Crt_Sig = '2B'; // Ed25519 sig appears in current list only.
|
|
37
|
+
this.ECDSA_256k1_Big_Sig = '2C'; // ECDSA secp256k1 sig appears in both lists.
|
|
38
|
+
this.ECDSA_256k1_Big_Crt_Sig = '2D'; // ECDSA secp256k1 sig appears in current list only.
|
|
39
|
+
this.ECDSA_256r1_Big_Sig = '2E'; // ECDSA secp256r1 sig appears in both lists.
|
|
40
|
+
this.ECDSA_256r1_Big_Crt_Sig = '2F'; // ECDSA secp256r1 sig appears in current list only.
|
|
41
|
+
this.Ed448_Big_Sig = '3A'; // Ed448 signature appears in both lists.
|
|
42
|
+
this.Ed448_Big_Crt_Sig = '3B'; // Ed448 signature appears in current list only.
|
|
43
|
+
}
|
|
44
|
+
has(prop) {
|
|
45
|
+
const m = new Map(Array.from(Object.entries(this), (v) => [v[1], v[0]]));
|
|
46
|
+
return m.has(prop);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export const IdxSigDex = new IndexedSigCodex();
|
|
50
|
+
export class IndexedCurrentSigCodex {
|
|
51
|
+
constructor() {
|
|
52
|
+
this.Ed25519_Crt_Sig = 'B'; // Ed25519 sig appears in current list only.
|
|
53
|
+
this.ECDSA_256k1_Crt_Sig = 'D'; // ECDSA secp256k1 sig appears in current list only.
|
|
54
|
+
this.ECDSA_256r1_Crt_Sig = 'F'; // ECDSA secp256r1 sig appears in current list.
|
|
55
|
+
this.Ed448_Crt_Sig = '0B'; // Ed448 signature appears in current list only.
|
|
56
|
+
this.Ed25519_Big_Crt_Sig = '2B'; // Ed25519 sig appears in current list only.
|
|
57
|
+
this.ECDSA_256k1_Big_Crt_Sig = '2D'; // ECDSA secp256k1 sig appears in current list only.
|
|
58
|
+
this.ECDSA_256r1_Big_Crt_Sig = '2F'; // ECDSA secp256r1 sig appears in current list only.
|
|
59
|
+
this.Ed448_Big_Crt_Sig = '3B'; // Ed448 signature appears in current list only.
|
|
60
|
+
}
|
|
61
|
+
has(prop) {
|
|
62
|
+
const m = new Map(Array.from(Object.entries(this), (v) => [v[1], v[0]]));
|
|
63
|
+
return m.has(prop);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export const IdxCrtSigDex = new IndexedCurrentSigCodex();
|
|
67
|
+
export class IndexedBothSigCodex {
|
|
68
|
+
constructor() {
|
|
69
|
+
this.Ed25519_Sig = 'A'; // Ed25519 sig appears same in both lists if any.
|
|
70
|
+
this.ECDSA_256k1_Sig = 'C'; // ECDSA secp256k1 sig appears same in both lists if any.
|
|
71
|
+
this.Ed448_Sig = '0A'; // Ed448 signature appears in both lists.
|
|
72
|
+
this.Ed25519_Big_Sig = '2A'; // Ed25519 sig appears in both listsy.
|
|
73
|
+
this.ECDSA_256k1_Big_Sig = '2C'; // ECDSA secp256k1 sig appears in both lists.
|
|
74
|
+
this.Ed448_Big_Sig = '3A'; // Ed448 signature appears in both lists.
|
|
75
|
+
}
|
|
76
|
+
has(prop) {
|
|
77
|
+
const m = new Map(Array.from(Object.entries(this), (v) => [v[1], v[0]]));
|
|
78
|
+
return m.has(prop);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export const IdxBthSigDex = new IndexedBothSigCodex();
|
|
82
|
+
export class Xizage {
|
|
83
|
+
constructor(hs, ss, os, fs, ls) {
|
|
84
|
+
this.hs = hs;
|
|
85
|
+
this.ss = ss;
|
|
86
|
+
this.os = os;
|
|
87
|
+
this.fs = fs;
|
|
88
|
+
this.ls = ls;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export class Indexer {
|
|
92
|
+
constructor({ raw = undefined, code = IdrDex.Ed25519_Sig, index = 0, ondex = undefined, qb64b = undefined, qb64 = undefined, qb2 = undefined, }) {
|
|
93
|
+
this.Codex = IdrDex;
|
|
94
|
+
this._code = '';
|
|
95
|
+
this._index = -1;
|
|
96
|
+
this._raw = new Uint8Array(0);
|
|
97
|
+
if (raw != undefined) {
|
|
98
|
+
if (code == undefined) {
|
|
99
|
+
throw new EmptyMaterialError(`Improper initialization need either (raw and code) or qb64b or qb64 or qb2.`);
|
|
100
|
+
}
|
|
101
|
+
if (!Indexer.Sizes.has(code)) {
|
|
102
|
+
throw new Error(`Unsupported code=${code}.`);
|
|
103
|
+
}
|
|
104
|
+
const xizage = Indexer.Sizes.get(code);
|
|
105
|
+
const os = xizage.os;
|
|
106
|
+
const fs = xizage.fs;
|
|
107
|
+
const cs = xizage.hs + xizage.ss;
|
|
108
|
+
const ms = xizage.ss - xizage.os;
|
|
109
|
+
if (!Number.isInteger(index) || index < 0 || index > 64 ** ms - 1) {
|
|
110
|
+
throw new Error(`Invalid index=${index} for code=${code}.`);
|
|
111
|
+
}
|
|
112
|
+
if (ondex != undefined &&
|
|
113
|
+
xizage.os != 0 &&
|
|
114
|
+
!(ondex >= 0 && ondex <= 64 ** os - 1)) {
|
|
115
|
+
throw new Error(`Invalid ondex=${ondex} for code=${code}.`);
|
|
116
|
+
}
|
|
117
|
+
if (IdxCrtSigDex.has(code) && ondex != undefined) {
|
|
118
|
+
throw new Error(`Non None ondex=${ondex} for code=${code}.`);
|
|
119
|
+
}
|
|
120
|
+
if (IdxBthSigDex.has(code)) {
|
|
121
|
+
if (ondex == undefined) {
|
|
122
|
+
ondex = index;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
if (ondex != index && os == 0) {
|
|
126
|
+
throw new Error(`Non matching ondex=${ondex} and index=${index} for code=${code}.`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (fs == undefined) {
|
|
131
|
+
throw new Error('variable length unsupported');
|
|
132
|
+
}
|
|
133
|
+
// TODO: Don't support this code
|
|
134
|
+
// if not fs: # compute fs from index
|
|
135
|
+
// if cs % 4:
|
|
136
|
+
// raise InvalidCodeSizeError(f"Whole code size not multiple of 4 for "
|
|
137
|
+
// f"variable length material. cs={cs}.")
|
|
138
|
+
// if os != 0:
|
|
139
|
+
// raise InvalidCodeSizeError(f"Non-zero other index size for "
|
|
140
|
+
// f"variable length material. os={os}.")
|
|
141
|
+
// fs = (index * 4) + cs
|
|
142
|
+
const rawsize = Math.floor(((fs - cs) * 3) / 4);
|
|
143
|
+
raw = raw.slice(0, rawsize);
|
|
144
|
+
if (raw.length != rawsize) {
|
|
145
|
+
throw new Error(`Not enougth raw bytes for code=${code} and index=${index} ,expected ${rawsize} got ${raw.length}.`);
|
|
146
|
+
}
|
|
147
|
+
this._code = code;
|
|
148
|
+
this._index = index;
|
|
149
|
+
this._ondex = ondex;
|
|
150
|
+
this._raw = raw;
|
|
151
|
+
}
|
|
152
|
+
else if (qb64b != undefined) {
|
|
153
|
+
const qb64 = d(qb64b);
|
|
154
|
+
this._exfil(qb64);
|
|
155
|
+
}
|
|
156
|
+
else if (qb64 != undefined) {
|
|
157
|
+
this._exfil(qb64);
|
|
158
|
+
}
|
|
159
|
+
else if (qb2 != undefined) {
|
|
160
|
+
this._bexfil(qb2);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
throw new EmptyMaterialError(`Improper initialization need either (raw and code and index) or qb64b or qb64 or qb2.`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
_bexfil(qb2) {
|
|
167
|
+
throw new Error(`qb2 not yet supported: ${qb2}`);
|
|
168
|
+
}
|
|
169
|
+
static _rawSize(code) {
|
|
170
|
+
const xizage = Indexer.Sizes.get(code);
|
|
171
|
+
return Math.floor(xizage.fs - ((xizage.hs + xizage.ss) * 3) / 4);
|
|
172
|
+
}
|
|
173
|
+
get code() {
|
|
174
|
+
return this._code;
|
|
175
|
+
}
|
|
176
|
+
get raw() {
|
|
177
|
+
return this._raw;
|
|
178
|
+
}
|
|
179
|
+
get index() {
|
|
180
|
+
return this._index;
|
|
181
|
+
}
|
|
182
|
+
get ondex() {
|
|
183
|
+
return this._ondex;
|
|
184
|
+
}
|
|
185
|
+
get qb64() {
|
|
186
|
+
return this._infil();
|
|
187
|
+
}
|
|
188
|
+
get qb64b() {
|
|
189
|
+
return b(this.qb64);
|
|
190
|
+
}
|
|
191
|
+
_infil() {
|
|
192
|
+
const code = this.code;
|
|
193
|
+
const index = this.index;
|
|
194
|
+
const ondex = this.ondex;
|
|
195
|
+
const raw = this.raw;
|
|
196
|
+
const ps = (3 - (raw.length % 3)) % 3;
|
|
197
|
+
const xizage = Indexer.Sizes.get(code);
|
|
198
|
+
const cs = xizage.hs + xizage.ss;
|
|
199
|
+
const ms = xizage.ss - xizage.os;
|
|
200
|
+
// TODO: don't support this code
|
|
201
|
+
// if not fs: # compute fs from index
|
|
202
|
+
// if cs % 4:
|
|
203
|
+
// raise InvalidCodeSizeError(f"Whole code size not multiple of 4 for "
|
|
204
|
+
// f"variable length material. cs={cs}.")
|
|
205
|
+
// if os != 0:
|
|
206
|
+
// raise InvalidCodeSizeError(f"Non-zero other index size for "
|
|
207
|
+
// f"variable length material. os={os}.")
|
|
208
|
+
// fs = (index * 4) + cs
|
|
209
|
+
if (index < 0 || index > 64 ** ms - 1) {
|
|
210
|
+
throw new Error(`Invalid index=${index} for code=${code}.`);
|
|
211
|
+
}
|
|
212
|
+
if (ondex != undefined &&
|
|
213
|
+
xizage.os != 0 &&
|
|
214
|
+
!(ondex >= 0 && ondex <= 64 ** xizage.os - 1)) {
|
|
215
|
+
throw new Error(`Invalid ondex=${ondex} for os=${xizage.os} and code=${code}.`);
|
|
216
|
+
}
|
|
217
|
+
const both = `${code}${intToB64(index, ms)}${intToB64(ondex == undefined ? 0 : ondex, xizage.os)}`;
|
|
218
|
+
if (both.length != cs) {
|
|
219
|
+
throw new Error(`Mismatch code size = ${cs} with table = ${both.length}.`);
|
|
220
|
+
}
|
|
221
|
+
if (cs % 4 != ps - xizage.ls) {
|
|
222
|
+
throw new Error(`Invalid code=${both} for converted raw pad size=${ps}.`);
|
|
223
|
+
}
|
|
224
|
+
const bytes = new Uint8Array(ps + raw.length);
|
|
225
|
+
for (let i = 0; i < ps; i++) {
|
|
226
|
+
bytes[i] = 0;
|
|
227
|
+
}
|
|
228
|
+
for (let i = 0; i < raw.length; i++) {
|
|
229
|
+
const odx = i + ps;
|
|
230
|
+
bytes[odx] = raw[i];
|
|
231
|
+
}
|
|
232
|
+
const full = both + encodeBase64Url(bytes).slice(ps - xizage.ls);
|
|
233
|
+
if (full.length != xizage.fs) {
|
|
234
|
+
throw new Error(`Invalid code=${both} for raw size=${raw.length}.`);
|
|
235
|
+
}
|
|
236
|
+
return full;
|
|
237
|
+
}
|
|
238
|
+
_exfil(qb64) {
|
|
239
|
+
if (qb64.length == 0) {
|
|
240
|
+
throw new Error('Empty Material');
|
|
241
|
+
}
|
|
242
|
+
const first = qb64[0];
|
|
243
|
+
if (!Array.from(Indexer.Hards.keys()).includes(first)) {
|
|
244
|
+
throw new Error(`Unexpected code ${first}`);
|
|
245
|
+
}
|
|
246
|
+
const hs = Indexer.Hards.get(first);
|
|
247
|
+
if (qb64.length < hs) {
|
|
248
|
+
throw new Error(`Need ${hs - qb64.length} more characters.`);
|
|
249
|
+
}
|
|
250
|
+
const hard = qb64.slice(0, hs);
|
|
251
|
+
if (!Array.from(Indexer.Sizes.keys()).includes(hard)) {
|
|
252
|
+
throw new Error(`Unsupported code ${hard}`);
|
|
253
|
+
}
|
|
254
|
+
const xizage = Indexer.Sizes.get(hard);
|
|
255
|
+
const cs = xizage.hs + xizage.ss; // both hard + soft code size
|
|
256
|
+
const ms = xizage.ss - xizage.os;
|
|
257
|
+
if (qb64.length < cs) {
|
|
258
|
+
throw new Error(`Need ${cs - qb64.length} more characters.`);
|
|
259
|
+
}
|
|
260
|
+
const sindex = qb64.slice(hs, hs + ms);
|
|
261
|
+
const index = b64ToInt(sindex);
|
|
262
|
+
const sondex = qb64.slice(hs + ms, hs + ms + xizage.os);
|
|
263
|
+
let ondex;
|
|
264
|
+
if (IdxCrtSigDex.has(hard)) {
|
|
265
|
+
ondex = xizage.os != 0 ? b64ToInt(sondex) : undefined;
|
|
266
|
+
if (ondex != 0 && ondex != undefined) {
|
|
267
|
+
throw new Error(`Invalid ondex=${ondex} for code=${hard}.`);
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
ondex = undefined;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
ondex = xizage.os != 0 ? b64ToInt(sondex) : index;
|
|
275
|
+
}
|
|
276
|
+
if (xizage.fs == undefined) {
|
|
277
|
+
throw new Error('variable length not supported');
|
|
278
|
+
}
|
|
279
|
+
// TODO: support variable length
|
|
280
|
+
// if not fs: # compute fs from index which means variable length
|
|
281
|
+
// if cs % 4:
|
|
282
|
+
// raise ValidationError(f"Whole code size not multiple of 4 for "
|
|
283
|
+
// f"variable length material. cs={cs}.")
|
|
284
|
+
// if os != 0:
|
|
285
|
+
// raise ValidationError(f"Non-zero other index size for "
|
|
286
|
+
// f"variable length material. os={os}.")
|
|
287
|
+
// fs = (index * 4) + cs
|
|
288
|
+
if (qb64.length < xizage.fs) {
|
|
289
|
+
throw new Error(`Need ${xizage.fs - qb64.length} more chars.`);
|
|
290
|
+
}
|
|
291
|
+
qb64 = qb64.slice(0, xizage.fs);
|
|
292
|
+
const ps = cs % 4;
|
|
293
|
+
const pbs = 2 * ps != 0 ? ps : xizage.ls;
|
|
294
|
+
let raw;
|
|
295
|
+
if (ps != 0) {
|
|
296
|
+
const base = new Array(ps + 1).join('A') + qb64.slice(cs);
|
|
297
|
+
const paw = decodeBase64Url(base); // decode base to leave prepadded raw
|
|
298
|
+
const pi = readInt(paw.slice(0, ps)); // prepad as int
|
|
299
|
+
if (pi & (2 ** pbs - 1)) {
|
|
300
|
+
// masked pad bits non-zero
|
|
301
|
+
throw new Error(`Non zeroed prepad bits = {pi & (2 ** pbs - 1 ):<06b} in {qb64b[cs:cs+1]}.`);
|
|
302
|
+
}
|
|
303
|
+
raw = paw.slice(ps); // strip off ps prepad paw bytes
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
const base = qb64.slice(cs);
|
|
307
|
+
const paw = decodeBase64Url(base);
|
|
308
|
+
const li = readInt(paw.slice(0, xizage.ls));
|
|
309
|
+
if (li != 0) {
|
|
310
|
+
if (li == 1) {
|
|
311
|
+
throw new Error(`Non zeroed lead byte = 0x{li:02x}.`);
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
throw new Error(`Non zeroed lead bytes = 0x{li:04x}`);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
raw = paw.slice(xizage.ls);
|
|
318
|
+
}
|
|
319
|
+
if (raw.length != Math.floor(((qb64.length - cs) * 3) / 4)) {
|
|
320
|
+
throw new Error(`Improperly qualified material = ${qb64}`);
|
|
321
|
+
}
|
|
322
|
+
this._code = hard;
|
|
323
|
+
this._index = index;
|
|
324
|
+
this._ondex = ondex;
|
|
325
|
+
this._raw = new Uint8Array(raw); // must be bytes for crpto opts and immutable not bytearray
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
Indexer.Hards = new Map([
|
|
329
|
+
['A', 1],
|
|
330
|
+
['B', 1],
|
|
331
|
+
['C', 1],
|
|
332
|
+
['D', 1],
|
|
333
|
+
['E', 1],
|
|
334
|
+
['F', 1],
|
|
335
|
+
['G', 1],
|
|
336
|
+
['H', 1],
|
|
337
|
+
['I', 1],
|
|
338
|
+
['J', 1],
|
|
339
|
+
['K', 1],
|
|
340
|
+
['L', 1],
|
|
341
|
+
['M', 1],
|
|
342
|
+
['N', 1],
|
|
343
|
+
['O', 1],
|
|
344
|
+
['P', 1],
|
|
345
|
+
['Q', 1],
|
|
346
|
+
['R', 1],
|
|
347
|
+
['S', 1],
|
|
348
|
+
['T', 1],
|
|
349
|
+
['U', 1],
|
|
350
|
+
['V', 1],
|
|
351
|
+
['W', 1],
|
|
352
|
+
['X', 1],
|
|
353
|
+
['Y', 1],
|
|
354
|
+
['Z', 1],
|
|
355
|
+
['a', 1],
|
|
356
|
+
['b', 1],
|
|
357
|
+
['c', 1],
|
|
358
|
+
['d', 1],
|
|
359
|
+
['e', 1],
|
|
360
|
+
['f', 1],
|
|
361
|
+
['g', 1],
|
|
362
|
+
['h', 1],
|
|
363
|
+
['i', 1],
|
|
364
|
+
['j', 1],
|
|
365
|
+
['k', 1],
|
|
366
|
+
['l', 1],
|
|
367
|
+
['m', 1],
|
|
368
|
+
['n', 1],
|
|
369
|
+
['o', 1],
|
|
370
|
+
['p', 1],
|
|
371
|
+
['q', 1],
|
|
372
|
+
['r', 1],
|
|
373
|
+
['s', 1],
|
|
374
|
+
['t', 1],
|
|
375
|
+
['u', 1],
|
|
376
|
+
['v', 1],
|
|
377
|
+
['w', 1],
|
|
378
|
+
['x', 1],
|
|
379
|
+
['y', 1],
|
|
380
|
+
['z', 1],
|
|
381
|
+
['0', 2],
|
|
382
|
+
['1', 2],
|
|
383
|
+
['2', 2],
|
|
384
|
+
['3', 2],
|
|
385
|
+
['4', 2],
|
|
386
|
+
]);
|
|
387
|
+
Indexer.Sizes = new Map(Object.entries({
|
|
388
|
+
A: new Xizage(1, 1, 0, 88, 0),
|
|
389
|
+
B: new Xizage(1, 1, 0, 88, 0),
|
|
390
|
+
C: new Xizage(1, 1, 0, 88, 0),
|
|
391
|
+
D: new Xizage(1, 1, 0, 88, 0),
|
|
392
|
+
E: new Xizage(1, 1, 0, 88, 0),
|
|
393
|
+
F: new Xizage(1, 1, 0, 88, 0),
|
|
394
|
+
'0A': new Xizage(2, 2, 1, 156, 0),
|
|
395
|
+
'0B': new Xizage(2, 2, 1, 156, 0),
|
|
396
|
+
'2A': new Xizage(2, 4, 2, 92, 0),
|
|
397
|
+
'2B': new Xizage(2, 4, 2, 92, 0),
|
|
398
|
+
'2C': new Xizage(2, 4, 2, 92, 0),
|
|
399
|
+
'2D': new Xizage(2, 4, 2, 92, 0),
|
|
400
|
+
'2E': new Xizage(2, 4, 2, 92, 0),
|
|
401
|
+
'2F': new Xizage(2, 4, 2, 92, 0),
|
|
402
|
+
'3A': new Xizage(2, 6, 3, 160, 0),
|
|
403
|
+
'3B': new Xizage(2, 6, 3, 160, 0),
|
|
404
|
+
'0z': new Xizage(2, 2, 0, undefined, 0),
|
|
405
|
+
'1z': new Xizage(2, 2, 1, 76, 1),
|
|
406
|
+
'4z': new Xizage(2, 6, 3, 80, 1),
|
|
407
|
+
}));
|