signify-ts 0.2.0 → 0.3.0-dev.e31e78d
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 +54 -18
- package/{src/keri/app/aiding.ts → dist/keri/app/aiding.js} +130 -236
- package/dist/keri/app/clienting.d.ts +59 -22
- package/{src/keri/app/clienting.ts → dist/keri/app/clienting.js} +146 -235
- package/dist/keri/app/contacting.d.ts +30 -23
- package/{src/keri/app/contacting.ts → dist/keri/app/contacting.js} +26 -63
- package/dist/keri/app/controller.d.ts +49 -6
- package/{src/keri/app/controller.ts → dist/keri/app/controller.js} +80 -186
- package/dist/keri/app/coring.d.ts +134 -25
- package/{src/keri/app/coring.ts → dist/keri/app/coring.js} +83 -56
- package/dist/keri/app/credentialing.d.ts +191 -67
- 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 +5 -3
- package/{src/keri/app/escrowing.ts → dist/keri/app/escrowing.js} +3 -9
- package/dist/keri/app/exchanging.d.ts +243 -11
- package/dist/keri/app/exchanging.js +242 -0
- package/dist/keri/app/grouping.d.ts +11 -9
- package/{src/keri/app/grouping.ts → dist/keri/app/grouping.js} +10 -29
- 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 +6 -6
- package/dist/keri/core/eventing.js +383 -0
- 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 +113 -46
- package/dist/keri/core/keeping.js +347 -0
- package/{src/keri/core/kering.ts → dist/keri/core/kering.js} +1 -3
- package/dist/keri/core/keyState.d.ts +98 -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 +2 -2
- package/{src/keri/core/number.ts → dist/keri/core/number.js} +26 -32
- 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 +44 -9
- package/dist/keri/core/salter.js +110 -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 +1158 -0
- package/dist/types/keria-api-schema.js +34 -0
- package/package.json +53 -52
- package/dist/math.d.ts +0 -1
- package/dist/signify-ts.cjs +0 -7835
- 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 -7811
- 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 -820
- package/src/keri/app/exchanging.ts +0 -220
- 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/eventing.ts +0 -581
- 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
- /package/dist/{buffer-polyfill.d.ts → keri/core/keyState.js} +0 -0
|
@@ -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<
|
|
31
|
+
* @returns {Promise<void>}
|
|
32
32
|
*/
|
|
33
33
|
delete(said: string): Promise<void>;
|
|
34
34
|
}
|
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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
|
|
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
|
|
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<
|
|
52
|
+
* @returns {Promise<void>}
|
|
63
53
|
*/
|
|
64
|
-
async delete(said
|
|
54
|
+
async delete(said) {
|
|
65
55
|
const path = `/notifications/` + said;
|
|
66
56
|
const method = 'DELETE';
|
|
67
|
-
await this.client.fetch(path, method,
|
|
57
|
+
await this.client.fetch(path, method, undefined);
|
|
68
58
|
}
|
|
69
59
|
}
|
|
@@ -1,26 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
38
|
-
input.fields
|
|
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
|
-
}
|
|
28
|
+
}
|
|
29
|
+
else if (field == '@path') {
|
|
43
30
|
items.push(`"${field}": ${path}`);
|
|
44
31
|
}
|
|
45
|
-
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
46
34
|
if (headers.has(field)) {
|
|
47
|
-
const value = normalize(headers.get(field)
|
|
35
|
+
const value = normalize(headers.get(field));
|
|
48
36
|
items.push(`"${field}": ${value}`);
|
|
49
37
|
}
|
|
50
38
|
}
|
|
51
39
|
});
|
|
52
|
-
const values = new Array
|
|
53
|
-
values.push(`(${input.fields
|
|
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
|
|
75
|
-
|
|
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,16 @@
|
|
|
1
|
+
import { fromByteArray, toByteArray } from 'base64-js';
|
|
2
|
+
export function encodeBase64Url(input) {
|
|
3
|
+
return fromByteArray(input)
|
|
4
|
+
.replace(/\+/g, '-')
|
|
5
|
+
.replace(/\//g, '_')
|
|
6
|
+
.replace(/=+/, '');
|
|
7
|
+
}
|
|
8
|
+
export function decodeBase64Url(input) {
|
|
9
|
+
if (!(typeof input === 'string')) {
|
|
10
|
+
throw new TypeError('`input` must be a string.');
|
|
11
|
+
}
|
|
12
|
+
const n = input.length % 4;
|
|
13
|
+
const padded = input + '='.repeat(n > 0 ? 4 - n : n);
|
|
14
|
+
const base64String = padded.replace(/-/g, '+').replace(/_/g, '/');
|
|
15
|
+
return toByteArray(base64String);
|
|
16
|
+
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { BexDex, Matter,
|
|
2
|
-
import { EmptyMaterialError } from
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import { BexDex, Matter, MtrDex } from "./matter.js";
|
|
2
|
+
import { EmptyMaterialError } from "./kering.js";
|
|
3
|
+
import { decodeBase64Url, encodeBase64Url } from "./base64.js";
|
|
4
|
+
import { concat } from "./core.js";
|
|
5
5
|
const B64REX = '^[A-Za-z0-9\\-_]*$';
|
|
6
6
|
export const Reb64 = new RegExp(B64REX);
|
|
7
|
-
|
|
8
7
|
/*
|
|
9
8
|
|
|
10
9
|
Bexter is subclass of Matter, cryptographic material, for variable length
|
|
@@ -80,59 +79,46 @@ export const Reb64 = new RegExp(B64REX);
|
|
|
80
79
|
|
|
81
80
|
|
|
82
81
|
*/
|
|
83
|
-
|
|
84
82
|
export class Bexter extends Matter {
|
|
85
|
-
constructor(
|
|
86
|
-
|
|
87
|
-
bext?: string
|
|
88
|
-
) {
|
|
89
|
-
if (
|
|
90
|
-
raw === undefined &&
|
|
83
|
+
constructor({ raw, code = MtrDex.StrB64_L0, qb64b, qb64, qb2 }, bext) {
|
|
84
|
+
if (raw === undefined &&
|
|
91
85
|
qb64b === undefined &&
|
|
92
86
|
qb64 === undefined &&
|
|
93
|
-
qb2 === undefined
|
|
94
|
-
) {
|
|
87
|
+
qb2 === undefined) {
|
|
95
88
|
if (bext === undefined)
|
|
96
89
|
throw new EmptyMaterialError('Missing bext string.');
|
|
97
|
-
|
|
98
90
|
const match = Reb64.exec(bext);
|
|
99
|
-
if (!match)
|
|
100
|
-
|
|
91
|
+
if (!match)
|
|
92
|
+
throw new Error('Invalid Base64.');
|
|
101
93
|
raw = Bexter._rawify(bext);
|
|
102
94
|
}
|
|
103
|
-
|
|
104
95
|
super({ raw, code, qb64b, qb64, qb2 });
|
|
105
|
-
|
|
106
96
|
if (!BexDex.has(this.code))
|
|
107
97
|
throw new Error(`Invalid code = ${this.code} for Bexter.`);
|
|
108
98
|
}
|
|
109
|
-
|
|
110
|
-
static _rawify(bext: string): Uint8Array {
|
|
99
|
+
static _rawify(bext) {
|
|
111
100
|
const ts = bext.length % 4; // bext size mod 4
|
|
112
101
|
const ws = (4 - ts) % 4; // pre conv wad size in chars
|
|
113
102
|
const ls = (3 - ts) % 3; // post conv lead size in bytes
|
|
114
103
|
const wad = new Array(ws);
|
|
115
104
|
wad.fill('A');
|
|
116
105
|
const base = wad.join('') + bext; // pre pad with wad of zeros in Base64 == 'A'
|
|
117
|
-
const raw =
|
|
118
|
-
|
|
106
|
+
const raw = decodeBase64Url(base); // [ls:] // convert and remove leader
|
|
119
107
|
return Uint8Array.from(raw).subarray(ls); // raw binary equivalent of text
|
|
120
108
|
}
|
|
121
|
-
|
|
122
|
-
get bext(): string {
|
|
109
|
+
get bext() {
|
|
123
110
|
const sizage = Matter.Sizes.get(this.code);
|
|
124
|
-
const wad = Uint8Array.from(new Array(sizage
|
|
125
|
-
const bext =
|
|
126
|
-
|
|
111
|
+
const wad = Uint8Array.from(new Array(sizage === null || sizage === void 0 ? void 0 : sizage.ls).fill(0));
|
|
112
|
+
const bext = encodeBase64Url(concat(wad, this.raw));
|
|
127
113
|
let ws = 0;
|
|
128
|
-
if (sizage
|
|
114
|
+
if ((sizage === null || sizage === void 0 ? void 0 : sizage.ls) === 0 && bext !== undefined) {
|
|
129
115
|
if (bext[0] === 'A') {
|
|
130
116
|
ws = 1;
|
|
131
117
|
}
|
|
132
|
-
} else {
|
|
133
|
-
ws = (sizage?.ls! + 1) % 4;
|
|
134
118
|
}
|
|
135
|
-
|
|
119
|
+
else {
|
|
120
|
+
ws = ((sizage === null || sizage === void 0 ? void 0 : sizage.ls) + 1) % 4;
|
|
121
|
+
}
|
|
136
122
|
return bext.substring(ws);
|
|
137
123
|
}
|
|
138
124
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Verfer } from './verfer';
|
|
2
|
-
import { Matter, MatterArgs } from './matter';
|
|
1
|
+
import { Verfer } from './verfer.ts';
|
|
2
|
+
import { Matter, MatterArgs } from './matter.ts';
|
|
3
3
|
export declare class Cigar extends Matter {
|
|
4
4
|
private _verfer;
|
|
5
5
|
constructor({ raw, code, qb64, qb64b, qb2 }: MatterArgs, verfer?: Verfer);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Matter } from "./matter.js";
|
|
2
|
+
export class Cigar extends Matter {
|
|
3
|
+
constructor({ raw, code, qb64, qb64b, qb2 }, verfer) {
|
|
4
|
+
super({ raw, code, qb64, qb64b, qb2 });
|
|
5
|
+
this._verfer = verfer;
|
|
6
|
+
}
|
|
7
|
+
get verfer() {
|
|
8
|
+
return this._verfer;
|
|
9
|
+
}
|
|
10
|
+
set verfer(verfer) {
|
|
11
|
+
this._verfer = verfer;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Matter, MatterArgs } from './matter';
|
|
1
|
+
import { Matter, MatterArgs } from './matter.ts';
|
|
2
2
|
export declare class Cipher extends Matter {
|
|
3
3
|
constructor({ raw, code, qb64, qb64b, qb2 }: MatterArgs);
|
|
4
4
|
decrypt(prikey?: Uint8Array | undefined, seed?: Uint8Array | undefined): any;
|
|
@@ -1,33 +1,24 @@
|
|
|
1
|
-
import { Matter,
|
|
2
|
-
import { Decrypter } from
|
|
3
|
-
|
|
1
|
+
import { Matter, MtrDex } from "./matter.js";
|
|
2
|
+
import { Decrypter } from "./decrypter.js";
|
|
4
3
|
export class Cipher extends Matter {
|
|
5
|
-
constructor({ raw, code, qb64, qb64b, qb2 }
|
|
4
|
+
constructor({ raw, code, qb64, qb64b, qb2 }) {
|
|
6
5
|
if (raw != undefined && code == undefined) {
|
|
7
6
|
if (raw.length == Matter._rawSize(MtrDex.X25519_Cipher_Salt)) {
|
|
8
7
|
code = MtrDex.X25519_Cipher_Salt;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
) {
|
|
8
|
+
}
|
|
9
|
+
else if (raw.length == Matter._rawSize(MtrDex.X25519_Cipher_Seed)) {
|
|
12
10
|
code = MtrDex.X25519_Cipher_Salt;
|
|
13
11
|
}
|
|
14
12
|
}
|
|
15
13
|
super({ raw: raw, code: code, qb64b: qb64b, qb64: qb64, qb2: qb2 });
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
MtrDex.X25519_Cipher_Seed,
|
|
21
|
-
]).includes(this.code)
|
|
22
|
-
) {
|
|
14
|
+
if (!Array.from([
|
|
15
|
+
MtrDex.X25519_Cipher_Salt,
|
|
16
|
+
MtrDex.X25519_Cipher_Seed,
|
|
17
|
+
]).includes(this.code)) {
|
|
23
18
|
throw new Error(`Unsupported Cipher code == ${this.code}`);
|
|
24
19
|
}
|
|
25
20
|
}
|
|
26
|
-
|
|
27
|
-
decrypt(
|
|
28
|
-
prikey: Uint8Array | undefined = undefined,
|
|
29
|
-
seed: Uint8Array | undefined = undefined
|
|
30
|
-
) {
|
|
21
|
+
decrypt(prikey = undefined, seed = undefined) {
|
|
31
22
|
const decrypter = new Decrypter({ qb64b: prikey }, seed);
|
|
32
23
|
return decrypter.decrypt(this.qb64b);
|
|
33
24
|
}
|