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
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { Counter, CtrDex } from
|
|
2
|
-
import { Seqner } from
|
|
3
|
-
import { Prefixer } from
|
|
4
|
-
import { Saider } from
|
|
5
|
-
|
|
6
|
-
import { b } from './core';
|
|
7
|
-
|
|
8
|
-
export function pad(n: any, width = 3, z = 0) {
|
|
1
|
+
import { Counter, CtrDex } from "./counter.js";
|
|
2
|
+
import { Seqner } from "./seqner.js";
|
|
3
|
+
import { Prefixer } from "./prefixer.js";
|
|
4
|
+
import { Saider } from "./saider.js";
|
|
5
|
+
export function pad(n, width = 3, z = 0) {
|
|
9
6
|
return (String(z).repeat(width) + String(n)).slice(String(n).length);
|
|
10
7
|
}
|
|
11
|
-
|
|
12
8
|
/**
|
|
13
9
|
* @description Returns list of depth first recursively extracted values from elements of
|
|
14
10
|
key event dict ked whose flabels are in lables list
|
|
@@ -16,22 +12,17 @@ export function pad(n: any, width = 3, z = 0) {
|
|
|
16
12
|
* @param {*} ked ked is key event dict
|
|
17
13
|
* @param {*} labels labels is list of element labels in ked from which to extract values
|
|
18
14
|
*/
|
|
19
|
-
export function extractValues(ked
|
|
15
|
+
export function extractValues(ked, labels) {
|
|
20
16
|
let values = [];
|
|
21
17
|
for (const label of labels) {
|
|
22
18
|
values = extractElementValues(ked[label], values);
|
|
23
19
|
}
|
|
24
|
-
|
|
25
20
|
return values;
|
|
26
21
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
ar1.length === ar2.length &&
|
|
31
|
-
ar1.every((val, index) => val === ar2[index])
|
|
32
|
-
);
|
|
22
|
+
export function arrayEquals(ar1, ar2) {
|
|
23
|
+
return (ar1.length === ar2.length &&
|
|
24
|
+
ar1.every((val, index) => val === ar2[index]));
|
|
33
25
|
}
|
|
34
|
-
|
|
35
26
|
/**
|
|
36
27
|
* @description Recusive depth first search that recursively extracts value(s) from element
|
|
37
28
|
and appends to values list
|
|
@@ -40,65 +31,55 @@ export function arrayEquals(ar1: Uint8Array, ar2: Uint8Array) {
|
|
|
40
31
|
* @param {*} element
|
|
41
32
|
* @param {*} values
|
|
42
33
|
*/
|
|
43
|
-
|
|
44
|
-
function extractElementValues(element: any, values: any) {
|
|
34
|
+
function extractElementValues(element, values) {
|
|
45
35
|
let data = [];
|
|
46
|
-
|
|
47
36
|
try {
|
|
48
37
|
if (element instanceof Array && !(typeof element == 'string')) {
|
|
49
|
-
for (const k in element)
|
|
50
|
-
|
|
38
|
+
for (const k in element)
|
|
39
|
+
extractElementValues(element[k], values);
|
|
40
|
+
}
|
|
41
|
+
else if (typeof element == 'string') {
|
|
51
42
|
values.push(element);
|
|
52
43
|
}
|
|
53
44
|
data = values;
|
|
54
|
-
} catch (error) {
|
|
55
|
-
throw new Error(error as string);
|
|
56
45
|
}
|
|
57
|
-
|
|
46
|
+
catch (error) {
|
|
47
|
+
throw new Error(error);
|
|
48
|
+
}
|
|
58
49
|
return data;
|
|
59
50
|
}
|
|
60
|
-
|
|
61
51
|
/**
|
|
62
52
|
* @description Returns True if obj is non-string iterable, False otherwise
|
|
63
53
|
|
|
64
54
|
* @param {*} obj
|
|
65
55
|
*/
|
|
66
|
-
|
|
67
56
|
// function nonStringIterable(obj) {
|
|
68
57
|
// obj instanceof (String)
|
|
69
58
|
// return instanceof(obj, (str, bytes)) && instanceof(obj, Iterable))
|
|
70
59
|
// }
|
|
71
|
-
|
|
72
|
-
export function nowUTC(): Date {
|
|
60
|
+
export function nowUTC() {
|
|
73
61
|
return new Date();
|
|
74
62
|
}
|
|
75
|
-
|
|
76
|
-
export function range(start: number, stop: number, step: number) {
|
|
63
|
+
export function range(start, stop, step) {
|
|
77
64
|
if (typeof stop == 'undefined') {
|
|
78
65
|
// one param defined
|
|
79
66
|
stop = start;
|
|
80
67
|
start = 0;
|
|
81
68
|
}
|
|
82
|
-
|
|
83
69
|
if (typeof step == 'undefined') {
|
|
84
70
|
step = 1;
|
|
85
71
|
}
|
|
86
|
-
|
|
87
72
|
if ((step > 0 && start >= stop) || (step < 0 && start <= stop)) {
|
|
88
73
|
return [];
|
|
89
74
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
for (let i: number = start; step > 0 ? i < stop : i > stop; i += step) {
|
|
75
|
+
const result = new Array();
|
|
76
|
+
for (let i = start; step > 0 ? i < stop : i > stop; i += step) {
|
|
93
77
|
result.push(i);
|
|
94
78
|
}
|
|
95
|
-
|
|
96
79
|
return result;
|
|
97
80
|
}
|
|
98
|
-
|
|
99
|
-
export function intToBytes(value: number, length: number): Uint8Array {
|
|
81
|
+
export function intToBytes(value, length) {
|
|
100
82
|
const byteArray = new Uint8Array(length); // Assuming a 4-byte integer (32 bits)
|
|
101
|
-
|
|
102
83
|
for (let index = byteArray.length - 1; index >= 0; index--) {
|
|
103
84
|
const byte = value & 0xff;
|
|
104
85
|
byteArray[index] = byte;
|
|
@@ -106,27 +87,23 @@ export function intToBytes(value: number, length: number): Uint8Array {
|
|
|
106
87
|
}
|
|
107
88
|
return byteArray;
|
|
108
89
|
}
|
|
109
|
-
|
|
110
|
-
export function bytesToInt(ar: Uint8Array): number {
|
|
90
|
+
export function bytesToInt(ar) {
|
|
111
91
|
let value = 0;
|
|
112
92
|
for (let i = 0; i < ar.length; i++) {
|
|
113
93
|
value = value * 256 + ar[i];
|
|
114
94
|
}
|
|
115
95
|
return value;
|
|
116
96
|
}
|
|
117
|
-
|
|
118
|
-
export function serializeACDCAttachment(anc: Serder): Uint8Array {
|
|
97
|
+
export function serializeACDCAttachment(anc) {
|
|
119
98
|
const prefixer = new Prefixer({ qb64: anc.pre });
|
|
120
99
|
const seqner = new Seqner({ sn: anc.sn });
|
|
121
|
-
const saider = new Saider({ qb64: anc.
|
|
100
|
+
const saider = new Saider({ qb64: anc.sad['d'] });
|
|
122
101
|
const craw = new Uint8Array();
|
|
123
102
|
const ctr = new Counter({ code: CtrDex.SealSourceTriples, count: 1 }).qb64b;
|
|
124
103
|
const prefix = prefixer.qb64b;
|
|
125
104
|
const seq = seqner.qb64b;
|
|
126
105
|
const said = saider.qb64b;
|
|
127
|
-
const newCraw = new Uint8Array(
|
|
128
|
-
craw.length + ctr.length + prefix.length + seq.length + said.length
|
|
129
|
-
);
|
|
106
|
+
const newCraw = new Uint8Array(craw.length + ctr.length + prefix.length + seq.length + said.length);
|
|
130
107
|
newCraw.set(craw);
|
|
131
108
|
newCraw.set(ctr, craw.length);
|
|
132
109
|
newCraw.set(prefix, craw.length + ctr.length);
|
|
@@ -134,13 +111,10 @@ export function serializeACDCAttachment(anc: Serder): Uint8Array {
|
|
|
134
111
|
newCraw.set(said, craw.length + ctr.length + prefix.length + seq.length);
|
|
135
112
|
return newCraw;
|
|
136
113
|
}
|
|
137
|
-
|
|
138
|
-
export function serializeIssExnAttachment(anc: Serder): Uint8Array {
|
|
114
|
+
export function serializeIssExnAttachment(anc) {
|
|
139
115
|
const seqner = new Seqner({ sn: anc.sn });
|
|
140
|
-
const ancSaider = new Saider({ qb64: anc.
|
|
141
|
-
const coupleArray = new Uint8Array(
|
|
142
|
-
seqner.qb64b.length + ancSaider.qb64b.length
|
|
143
|
-
);
|
|
116
|
+
const ancSaider = new Saider({ qb64: anc.sad['d'] });
|
|
117
|
+
const coupleArray = new Uint8Array(seqner.qb64b.length + ancSaider.qb64b.length);
|
|
144
118
|
coupleArray.set(seqner.qb64b);
|
|
145
119
|
coupleArray.set(ancSaider.qb64b, seqner.qb64b.length);
|
|
146
120
|
const counter = new Counter({
|
|
@@ -151,11 +125,8 @@ export function serializeIssExnAttachment(anc: Serder): Uint8Array {
|
|
|
151
125
|
const atc = new Uint8Array(counter.qb64b.length + coupleArray.length);
|
|
152
126
|
atc.set(counterQb64b);
|
|
153
127
|
atc.set(coupleArray, counterQb64b.length);
|
|
154
|
-
|
|
155
128
|
if (atc.length % 4 !== 0) {
|
|
156
|
-
throw new Error(
|
|
157
|
-
`Invalid attachments size: ${atc.length}, non-integral quadlets detected.`
|
|
158
|
-
);
|
|
129
|
+
throw new Error(`Invalid attachments size: ${atc.length}, non-integral quadlets detected.`);
|
|
159
130
|
}
|
|
160
131
|
const pcnt = new Counter({
|
|
161
132
|
code: CtrDex.AttachedMaterialQuadlets,
|
|
@@ -164,6 +135,5 @@ export function serializeIssExnAttachment(anc: Serder): Uint8Array {
|
|
|
164
135
|
const msg = new Uint8Array(pcnt.qb64b.length + atc.length);
|
|
165
136
|
msg.set(pcnt.qb64b);
|
|
166
137
|
msg.set(atc, pcnt.qb64b.length);
|
|
167
|
-
|
|
168
138
|
return msg;
|
|
169
139
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { randomNonce } from "../app/coring.js";
|
|
2
|
+
import { TraitDex } from "../app/habery.js";
|
|
3
|
+
import { Serials, Vrsn_1_0, Protocols, versify, Ilks, } from "../core/core.js";
|
|
4
|
+
import { ample } from "./eventing.js";
|
|
5
|
+
import { MtrDex } from "./matter.js";
|
|
6
|
+
import { Prefixer } from "./prefixer.js";
|
|
7
|
+
import { Serder } from "./serder.js";
|
|
8
|
+
var vdr;
|
|
9
|
+
(function (vdr) {
|
|
10
|
+
function incept({ pre, toad, nonce = randomNonce(), baks = [], cnfg = [], version = Vrsn_1_0, kind = Serials.JSON, code = MtrDex.Blake3_256, }) {
|
|
11
|
+
const vs = versify(Protocols.KERI, version, kind, 0);
|
|
12
|
+
const isn = 0;
|
|
13
|
+
const ilk = Ilks.vcp;
|
|
14
|
+
if (cnfg.includes(TraitDex.NoBackers) && baks.length > 0) {
|
|
15
|
+
throw new Error(`${baks.length} backers specified for NB vcp, 0 allowed`);
|
|
16
|
+
}
|
|
17
|
+
if (new Set(baks).size < baks.length) {
|
|
18
|
+
throw new Error(`Invalid baks ${baks} has duplicates`);
|
|
19
|
+
}
|
|
20
|
+
let _toad;
|
|
21
|
+
if (toad === undefined) {
|
|
22
|
+
if (baks.length === 0) {
|
|
23
|
+
_toad = 0;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
_toad = ample(baks.length);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
_toad = +toad;
|
|
31
|
+
}
|
|
32
|
+
if (baks.length > 0) {
|
|
33
|
+
if (_toad < 1 || _toad > baks.length) {
|
|
34
|
+
throw new Error(`Invalid toad ${_toad} for baks in ${baks}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
if (_toad != 0) {
|
|
39
|
+
throw new Error(`Invalid toad ${_toad} for no baks`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const sad = {
|
|
43
|
+
v: vs,
|
|
44
|
+
t: ilk,
|
|
45
|
+
d: '',
|
|
46
|
+
i: '',
|
|
47
|
+
ii: pre,
|
|
48
|
+
s: '' + isn,
|
|
49
|
+
c: cnfg,
|
|
50
|
+
bt: _toad.toString(16),
|
|
51
|
+
b: baks,
|
|
52
|
+
n: nonce,
|
|
53
|
+
};
|
|
54
|
+
const prefixer = new Prefixer({ code }, sad);
|
|
55
|
+
sad.i = prefixer.qb64;
|
|
56
|
+
sad.d = prefixer.qb64;
|
|
57
|
+
return new Serder(sad);
|
|
58
|
+
}
|
|
59
|
+
vdr.incept = incept;
|
|
60
|
+
})(vdr || (vdr = {}));
|
|
61
|
+
export { vdr };
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import { Matter, MatterArgs } from './matter';
|
|
1
|
+
import { Matter, MatterArgs } from './matter.ts';
|
|
3
2
|
/**
|
|
4
3
|
* @description Verfer :sublclass of Matter,helps to verify signature of serialization
|
|
5
4
|
* using .raw as verifier key and .code as signature cypher suite
|
|
6
5
|
*/
|
|
7
6
|
export declare class Verfer extends Matter {
|
|
8
|
-
private readonly _verify;
|
|
9
7
|
constructor({ raw, code, qb64, qb64b, qb2 }: MatterArgs);
|
|
10
|
-
verify(sig:
|
|
11
|
-
_ed25519(sig: any, ser: any, key: any): boolean;
|
|
12
|
-
_secp256r1(sig: any, ser: any, key: any): any;
|
|
8
|
+
verify(sig: Uint8Array, ser: Uint8Array | string): boolean;
|
|
13
9
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import libsodium from 'libsodium-wrappers-sumo';
|
|
2
|
+
import { Matter, MtrDex } from "./matter.js";
|
|
3
|
+
import { p256 } from '@noble/curves/p256';
|
|
4
|
+
import { b } from "./core.js";
|
|
5
|
+
const VERFER_CODES = new Set([
|
|
6
|
+
MtrDex.Ed25519N,
|
|
7
|
+
MtrDex.Ed25519,
|
|
8
|
+
MtrDex.ECDSA_256r1N,
|
|
9
|
+
MtrDex.ECDSA_256r1,
|
|
10
|
+
]);
|
|
11
|
+
/**
|
|
12
|
+
* @description Verfer :sublclass of Matter,helps to verify signature of serialization
|
|
13
|
+
* using .raw as verifier key and .code as signature cypher suite
|
|
14
|
+
*/
|
|
15
|
+
export class Verfer extends Matter {
|
|
16
|
+
constructor({ raw, code, qb64, qb64b, qb2 }) {
|
|
17
|
+
super({ raw, code, qb64, qb64b, qb2 });
|
|
18
|
+
if (!VERFER_CODES.has(this.code)) {
|
|
19
|
+
throw new Error(`Unsupported code = ${this.code} for verifier.`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
verify(sig, ser) {
|
|
23
|
+
switch (this.code) {
|
|
24
|
+
case MtrDex.Ed25519:
|
|
25
|
+
case MtrDex.Ed25519N: {
|
|
26
|
+
return libsodium.crypto_sign_verify_detached(sig, ser, this.raw);
|
|
27
|
+
}
|
|
28
|
+
case MtrDex.ECDSA_256r1:
|
|
29
|
+
case MtrDex.ECDSA_256r1N: {
|
|
30
|
+
const message = typeof ser === 'string' ? b(ser) : ser;
|
|
31
|
+
return p256.verify(sig, message, this.raw);
|
|
32
|
+
}
|
|
33
|
+
default:
|
|
34
|
+
throw new Error(`Unsupported code = ${this.code} for verifier.`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import { Siger } from '../core/siger.ts';
|
|
2
|
+
import { Cigar } from '../core/cigar.ts';
|
|
1
3
|
export declare const FALSY: (string | number | boolean)[];
|
|
2
4
|
export declare const TRUTHY: (string | number | boolean)[];
|
|
3
5
|
export declare class Signage {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
readonly markers: (Siger | Cigar)[] | Map<string, string | Siger | Cigar>;
|
|
7
|
+
readonly indexed?: boolean | undefined;
|
|
8
|
+
readonly signer?: string | undefined;
|
|
9
|
+
readonly ordinal?: string | undefined;
|
|
10
|
+
readonly digest?: string | undefined;
|
|
11
|
+
readonly kind?: string | undefined;
|
|
12
|
+
constructor(markers: (Siger | Cigar)[] | Map<string, string | Siger | Cigar>, indexed?: boolean | undefined, signer?: string | undefined, ordinal?: string | undefined, digest?: string | undefined, kind?: string | undefined);
|
|
11
13
|
}
|
|
12
|
-
export declare function signature(signages:
|
|
14
|
+
export declare function signature(signages: Signage[]): Headers;
|
|
13
15
|
export declare function designature(value: string): Signage[];
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { Siger } from "../core/siger.js";
|
|
2
|
+
import { Cigar } from "../core/cigar.js";
|
|
3
|
+
export const FALSY = [false, 0, '?0', 'no', 'false', 'False', 'off'];
|
|
4
|
+
export const TRUTHY = [true, 1, '?1', 'yes', 'true', 'True', 'on'];
|
|
5
|
+
export class Signage {
|
|
6
|
+
constructor(markers, indexed, signer, ordinal, digest, kind) {
|
|
7
|
+
this.markers = markers;
|
|
8
|
+
this.indexed = indexed;
|
|
9
|
+
this.signer = signer;
|
|
10
|
+
this.ordinal = ordinal;
|
|
11
|
+
this.digest = digest;
|
|
12
|
+
this.kind = kind;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function signature(signages) {
|
|
16
|
+
var _a;
|
|
17
|
+
const values = [];
|
|
18
|
+
for (const signage of signages) {
|
|
19
|
+
let markers;
|
|
20
|
+
let tags;
|
|
21
|
+
if (signage.markers instanceof Map) {
|
|
22
|
+
markers = Array.from(signage.markers.values());
|
|
23
|
+
tags = Array.from(signage.markers.keys());
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
markers = signage.markers;
|
|
27
|
+
tags = [];
|
|
28
|
+
}
|
|
29
|
+
const items = new Array();
|
|
30
|
+
const indexed = (_a = signage.indexed) !== null && _a !== void 0 ? _a : markers[0] instanceof Siger;
|
|
31
|
+
if (indexed) {
|
|
32
|
+
items.push('indexed="?1"');
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
items.push('indexed="?0"');
|
|
36
|
+
}
|
|
37
|
+
if (signage.signer != undefined) {
|
|
38
|
+
items.push(`signer="${signage.signer}"`);
|
|
39
|
+
}
|
|
40
|
+
if (signage.ordinal != undefined) {
|
|
41
|
+
items.push(`ordinal="${signage.ordinal}"`);
|
|
42
|
+
}
|
|
43
|
+
if (signage.digest != undefined) {
|
|
44
|
+
items.push(`digest="${signage.digest}"`);
|
|
45
|
+
}
|
|
46
|
+
if (signage.kind != undefined) {
|
|
47
|
+
items.push(`kind="${signage.kind}"`);
|
|
48
|
+
}
|
|
49
|
+
items.push(...markers.map((marker, idx) => {
|
|
50
|
+
let tag = undefined;
|
|
51
|
+
let val;
|
|
52
|
+
if (tags != undefined && tags.length > idx) {
|
|
53
|
+
tag = tags[idx];
|
|
54
|
+
}
|
|
55
|
+
if (marker instanceof Siger) {
|
|
56
|
+
if (!indexed) {
|
|
57
|
+
throw new Error(`Indexed signature marker ${marker} when indexed False.`);
|
|
58
|
+
}
|
|
59
|
+
tag = tag !== null && tag !== void 0 ? tag : marker.index.toString();
|
|
60
|
+
val = marker.qb64;
|
|
61
|
+
}
|
|
62
|
+
else if (marker instanceof Cigar) {
|
|
63
|
+
if (indexed) {
|
|
64
|
+
throw new Error(`Unindexed signature marker ${marker} when indexed True.`);
|
|
65
|
+
}
|
|
66
|
+
if (!marker.verfer) {
|
|
67
|
+
throw new Error(`Indexed signature marker is missing verfer`);
|
|
68
|
+
}
|
|
69
|
+
tag = tag !== null && tag !== void 0 ? tag : marker.verfer.qb64;
|
|
70
|
+
val = marker.qb64;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
tag = tag !== null && tag !== void 0 ? tag : idx.toString();
|
|
74
|
+
val = marker;
|
|
75
|
+
}
|
|
76
|
+
return `${tag}="${val}"`;
|
|
77
|
+
}));
|
|
78
|
+
values.push(items.join(';'));
|
|
79
|
+
}
|
|
80
|
+
return new Headers([['Signature', values.join(',')]]);
|
|
81
|
+
}
|
|
82
|
+
export function designature(value) {
|
|
83
|
+
const values = value.replace(' ', '').split(',');
|
|
84
|
+
const signages = values.map((val) => {
|
|
85
|
+
const dict = new Map();
|
|
86
|
+
val.split(';').forEach((v) => {
|
|
87
|
+
const splits = v.split('=', 2);
|
|
88
|
+
dict.set(splits[0], splits[1].replaceAll('"', ''));
|
|
89
|
+
});
|
|
90
|
+
if (!dict.has('indexed')) {
|
|
91
|
+
throw new Error('Missing indexed field in Signature header signage.');
|
|
92
|
+
}
|
|
93
|
+
const item = dict.get('indexed');
|
|
94
|
+
const indexed = !FALSY.includes(item);
|
|
95
|
+
dict.delete('indexed');
|
|
96
|
+
let signer;
|
|
97
|
+
if (dict.has('signer')) {
|
|
98
|
+
signer = dict.get('signer');
|
|
99
|
+
dict.delete('signer');
|
|
100
|
+
}
|
|
101
|
+
let ordinal;
|
|
102
|
+
if (dict.has('ordinal')) {
|
|
103
|
+
ordinal = dict.get('ordinal');
|
|
104
|
+
dict.delete('ordinal');
|
|
105
|
+
}
|
|
106
|
+
let digest;
|
|
107
|
+
if (dict.has('digest')) {
|
|
108
|
+
digest = dict.get('digest');
|
|
109
|
+
dict.delete('digest');
|
|
110
|
+
}
|
|
111
|
+
let kind;
|
|
112
|
+
if (dict.has('kind')) {
|
|
113
|
+
kind = dict.get('kind');
|
|
114
|
+
dict.delete('kind');
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
kind = 'CESR';
|
|
118
|
+
}
|
|
119
|
+
if (kind == 'CESR') {
|
|
120
|
+
const markers = new Map();
|
|
121
|
+
for (const [key, val] of dict.entries()) {
|
|
122
|
+
if (indexed) {
|
|
123
|
+
markers.set(key, new Siger({ qb64: val }));
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
markers.set(key, new Cigar({ qb64: val }));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return new Signage(markers, indexed, signer, ordinal, digest, kind);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
return new Signage(dict, indexed, signer, ordinal, digest, kind);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
return signages;
|
|
136
|
+
}
|