signify-ts 0.2.1 → 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 +187 -69
- 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 -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/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
package/dist/keri/core/core.d.ts
CHANGED
|
@@ -1,16 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialization types supported by the KERI and ACDC protocols and this Signify implementation.
|
|
3
|
+
*/
|
|
1
4
|
export declare enum Serials {
|
|
2
5
|
JSON = "JSON"
|
|
3
6
|
}
|
|
4
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Protocol types supported by the KERI and ACDC protocols and this Signify implementation.
|
|
9
|
+
*/
|
|
10
|
+
export declare enum Protocols {
|
|
5
11
|
KERI = "KERI",
|
|
6
12
|
ACDC = "ACDC"
|
|
7
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Represents a protocol version of the KERI, ACDC, or other protocol specified in a CESR version string.
|
|
16
|
+
*/
|
|
8
17
|
export declare class Version {
|
|
9
18
|
major: number;
|
|
10
19
|
minor: number;
|
|
11
20
|
constructor(major?: number, minor?: number);
|
|
12
21
|
}
|
|
13
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Denotes version 1.0 of a protocol.
|
|
24
|
+
*/
|
|
25
|
+
export declare const Vrsn_1_0: Version;
|
|
26
|
+
/**
|
|
27
|
+
* Types of KERI and ACDC events.
|
|
28
|
+
*/
|
|
14
29
|
export declare const Ilks: {
|
|
15
30
|
icp: string;
|
|
16
31
|
rot: string;
|
|
@@ -24,36 +39,129 @@ export declare const Ilks: {
|
|
|
24
39
|
vcp: string;
|
|
25
40
|
iss: string;
|
|
26
41
|
rev: string;
|
|
42
|
+
bis: string;
|
|
43
|
+
brv: string;
|
|
27
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* Field labels for an inception event in V1 of the KERI protocol.
|
|
47
|
+
*/
|
|
28
48
|
export declare const IcpLabels: string[];
|
|
49
|
+
/**
|
|
50
|
+
* Field labels for an delegated inception event in V1 of the KERI protocol.
|
|
51
|
+
*/
|
|
29
52
|
export declare const DipLabels: string[];
|
|
53
|
+
/**
|
|
54
|
+
* Field labels for a rotation event in V1 of the KERI protocol.
|
|
55
|
+
*/
|
|
30
56
|
export declare const RotLabels: string[];
|
|
57
|
+
/**
|
|
58
|
+
* Field labels for an delegated rotation event in V1 of the KERI protocol.
|
|
59
|
+
*/
|
|
31
60
|
export declare const DrtLabels: string[];
|
|
61
|
+
/**
|
|
62
|
+
* Field labels for an interaction event in V1 of the KERI protocol.
|
|
63
|
+
*/
|
|
32
64
|
export declare const IxnLabels: string[];
|
|
65
|
+
/**
|
|
66
|
+
* Field labels for a key state notice event in V1 of the KERI protocol.
|
|
67
|
+
*/
|
|
33
68
|
export declare const KsnLabels: string[];
|
|
69
|
+
/**
|
|
70
|
+
* Field labels for a reply event in V1 of the KERI protocol.
|
|
71
|
+
*/
|
|
34
72
|
export declare const RpyLabels: string[];
|
|
73
|
+
/**
|
|
74
|
+
* Full size of a CESR version string in bytes.
|
|
75
|
+
*/
|
|
35
76
|
export declare const VERFULLSIZE = 17;
|
|
77
|
+
/**
|
|
78
|
+
* Minimum number of bytes a CESR parser must sniff to receive the entire version string.
|
|
79
|
+
*/
|
|
36
80
|
export declare const MINSNIFFSIZE: number;
|
|
37
81
|
export declare const MINSIGSIZE = 4;
|
|
82
|
+
/**
|
|
83
|
+
* Regular expression for a version 1 CESR object version string.
|
|
84
|
+
*/
|
|
38
85
|
export declare const VEREX = "(KERI|ACDC)([0-9a-f])([0-9a-f])([A-Z]{4})([0-9a-f]{6})_";
|
|
86
|
+
/**
|
|
87
|
+
* An interface for a basic dictionary type keyed by string with any value type.
|
|
88
|
+
* Mimics the Python dictionary type.
|
|
89
|
+
*/
|
|
39
90
|
export interface Dict<TValue> {
|
|
40
91
|
[id: string]: TValue;
|
|
41
92
|
}
|
|
42
93
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* @param {string} versionString
|
|
46
|
-
* @return {Object}
|
|
47
|
-
*
|
|
94
|
+
* Parses a serialization version string into the protocol, protocol version, serialization type, and raw size.
|
|
95
|
+
* Uses regex matchers to validate and extract version string parts.
|
|
96
|
+
* @param {string} versionString version string
|
|
97
|
+
* @return {Object} tuple of prototol (KERI or ACDC), kind of serialization like cbor,json, or mgpk,
|
|
98
|
+
* protocol version, and raw size of serialization
|
|
99
|
+
*/
|
|
100
|
+
export declare function deversify(versionString: string): [Protocols, Serials, Version, string];
|
|
101
|
+
/**
|
|
102
|
+
* Returns a valid KERI serialization version string specifying the protocol,
|
|
103
|
+
* protocol version, serialization type, and raw byte size of the serialization.
|
|
104
|
+
*
|
|
105
|
+
* Defaults to version 1.0.
|
|
106
|
+
* @param ident
|
|
107
|
+
* @param version
|
|
108
|
+
* @param kind
|
|
109
|
+
* @param size
|
|
110
|
+
*/
|
|
111
|
+
export declare function versify(ident?: Protocols, version?: Version, kind?: Serials, size?: number): string;
|
|
112
|
+
/**
|
|
113
|
+
* Map allowing lookup of Base64URLSafe characters by index.
|
|
48
114
|
*/
|
|
49
|
-
export declare function deversify(versionString: string): [Ident, Serials, Version, string];
|
|
50
|
-
export declare function versify(ident?: Ident, version?: Version, kind?: Serials, size?: number): string;
|
|
51
115
|
export declare const B64ChrByIdx: Map<number, string>;
|
|
116
|
+
/**
|
|
117
|
+
* Map allowing lookup of Base64URLSafe index by character.
|
|
118
|
+
*/
|
|
52
119
|
export declare const B64IdxByChr: Map<string, number>;
|
|
120
|
+
/**
|
|
121
|
+
* Converts an integer to a Base64URLSafe encoded string, left padded as specified.
|
|
122
|
+
* @param i integer to convert
|
|
123
|
+
* @param l minimum length of Base64 digits left padded with Base64 0 == 'A' character.
|
|
124
|
+
*/
|
|
53
125
|
export declare function intToB64(i: number, l?: number): string;
|
|
126
|
+
/**
|
|
127
|
+
* Converts an integer to a Base64URLSafe encoded string to a byte array, left padded as specified.
|
|
128
|
+
* @param i integer to convert
|
|
129
|
+
* @param l minimum length of Base64 digits left padded with Base64 0 == 'A' character.
|
|
130
|
+
*/
|
|
54
131
|
export declare function intToB64b(n: number, l?: number): Uint8Array;
|
|
132
|
+
/**
|
|
133
|
+
* Converts a Base64URLSafe encoded string to an integer.
|
|
134
|
+
* @param s string to convert
|
|
135
|
+
*/
|
|
55
136
|
export declare function b64ToInt(s: string): number;
|
|
137
|
+
/**
|
|
138
|
+
* Converts a UTF-8 string to bytes.
|
|
139
|
+
* Output is an encoded array of bytes. Assumes UTF-8 encoding.
|
|
140
|
+
* @param s string to be encoded as an array of bytes
|
|
141
|
+
*/
|
|
56
142
|
export declare function b(s?: string): Uint8Array;
|
|
143
|
+
/**
|
|
144
|
+
* Convert bytes to UTF-8 string.
|
|
145
|
+
* @param u array of bytes to be converted to UTF-8 string.
|
|
146
|
+
*/
|
|
57
147
|
export declare function d(u?: Uint8Array): string;
|
|
148
|
+
/**
|
|
149
|
+
* Concatenates two byte arrays together in a new byte array.
|
|
150
|
+
* @param one first byte array to be concatenated
|
|
151
|
+
* @param two second byte array to be concatenated
|
|
152
|
+
*/
|
|
58
153
|
export declare function concat(one: Uint8Array, two: Uint8Array): Uint8Array;
|
|
154
|
+
/**
|
|
155
|
+
* Converts a big-endian byte array into an integer.
|
|
156
|
+
*
|
|
157
|
+
* @param array - A `Uint8Array` of bytes representing a big-endian integer.
|
|
158
|
+
* @returns The integer represented by the byte array.
|
|
159
|
+
*
|
|
160
|
+
* Example:
|
|
161
|
+
* readInt(Uint8Array([0x01, 0x02, 0x03])) // returns 66051
|
|
162
|
+
*
|
|
163
|
+
* How it works:
|
|
164
|
+
* - The function interprets the array as a big-endian number.
|
|
165
|
+
* - Each byte is added to the integer after shifting the previous value left by 8 bits (multiplying by 256).
|
|
166
|
+
*/
|
|
59
167
|
export declare function readInt(array: Uint8Array): number;
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialization types supported by the KERI and ACDC protocols and this Signify implementation.
|
|
3
|
+
*/
|
|
4
|
+
export var Serials;
|
|
5
|
+
(function (Serials) {
|
|
6
|
+
Serials["JSON"] = "JSON";
|
|
7
|
+
})(Serials || (Serials = {}));
|
|
8
|
+
/**
|
|
9
|
+
* Protocol types supported by the KERI and ACDC protocols and this Signify implementation.
|
|
10
|
+
*/
|
|
11
|
+
export var Protocols;
|
|
12
|
+
(function (Protocols) {
|
|
13
|
+
Protocols["KERI"] = "KERI";
|
|
14
|
+
Protocols["ACDC"] = "ACDC";
|
|
15
|
+
})(Protocols || (Protocols = {}));
|
|
16
|
+
/**
|
|
17
|
+
* Represents a protocol version of the KERI, ACDC, or other protocol specified in a CESR version string.
|
|
18
|
+
*/
|
|
19
|
+
export class Version {
|
|
20
|
+
constructor(major = 1, minor = 0) {
|
|
21
|
+
this.major = major;
|
|
22
|
+
this.minor = minor;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Denotes version 1.0 of a protocol.
|
|
27
|
+
*/
|
|
28
|
+
export const Vrsn_1_0 = new Version();
|
|
29
|
+
/**
|
|
30
|
+
* Types of KERI and ACDC events.
|
|
31
|
+
*/
|
|
32
|
+
export const Ilks = {
|
|
33
|
+
icp: 'icp',
|
|
34
|
+
rot: 'rot',
|
|
35
|
+
ixn: 'ixn',
|
|
36
|
+
dip: 'dip',
|
|
37
|
+
drt: 'drt',
|
|
38
|
+
rct: 'rct',
|
|
39
|
+
vrc: 'vrc',
|
|
40
|
+
rpy: 'rpy',
|
|
41
|
+
exn: 'exn',
|
|
42
|
+
vcp: 'vcp',
|
|
43
|
+
iss: 'iss',
|
|
44
|
+
rev: 'rev',
|
|
45
|
+
bis: 'bis',
|
|
46
|
+
brv: 'brv',
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Field labels for an inception event in V1 of the KERI protocol.
|
|
50
|
+
*/
|
|
51
|
+
export const IcpLabels = [
|
|
52
|
+
'v',
|
|
53
|
+
'i',
|
|
54
|
+
's',
|
|
55
|
+
't',
|
|
56
|
+
'kt',
|
|
57
|
+
'k',
|
|
58
|
+
'n',
|
|
59
|
+
'bt',
|
|
60
|
+
'b',
|
|
61
|
+
'c',
|
|
62
|
+
'a',
|
|
63
|
+
];
|
|
64
|
+
/**
|
|
65
|
+
* Field labels for an delegated inception event in V1 of the KERI protocol.
|
|
66
|
+
*/
|
|
67
|
+
export const DipLabels = [
|
|
68
|
+
'v',
|
|
69
|
+
'i',
|
|
70
|
+
's',
|
|
71
|
+
't',
|
|
72
|
+
'kt',
|
|
73
|
+
'k',
|
|
74
|
+
'n',
|
|
75
|
+
'bt',
|
|
76
|
+
'b',
|
|
77
|
+
'c',
|
|
78
|
+
'a',
|
|
79
|
+
'di',
|
|
80
|
+
];
|
|
81
|
+
/**
|
|
82
|
+
* Field labels for a rotation event in V1 of the KERI protocol.
|
|
83
|
+
*/
|
|
84
|
+
export const RotLabels = [
|
|
85
|
+
'v',
|
|
86
|
+
'i',
|
|
87
|
+
's',
|
|
88
|
+
't',
|
|
89
|
+
'p',
|
|
90
|
+
'kt',
|
|
91
|
+
'k',
|
|
92
|
+
'n',
|
|
93
|
+
'bt',
|
|
94
|
+
'br',
|
|
95
|
+
'ba',
|
|
96
|
+
'a',
|
|
97
|
+
];
|
|
98
|
+
/**
|
|
99
|
+
* Field labels for an delegated rotation event in V1 of the KERI protocol.
|
|
100
|
+
*/
|
|
101
|
+
export const DrtLabels = [
|
|
102
|
+
'v',
|
|
103
|
+
'i',
|
|
104
|
+
's',
|
|
105
|
+
't',
|
|
106
|
+
'p',
|
|
107
|
+
'kt',
|
|
108
|
+
'k',
|
|
109
|
+
'n',
|
|
110
|
+
'bt',
|
|
111
|
+
'br',
|
|
112
|
+
'ba',
|
|
113
|
+
'a',
|
|
114
|
+
];
|
|
115
|
+
/**
|
|
116
|
+
* Field labels for an interaction event in V1 of the KERI protocol.
|
|
117
|
+
*/
|
|
118
|
+
export const IxnLabels = ['v', 'i', 's', 't', 'p', 'a'];
|
|
119
|
+
/**
|
|
120
|
+
* Field labels for a key state notice event in V1 of the KERI protocol.
|
|
121
|
+
*/
|
|
122
|
+
export const KsnLabels = [
|
|
123
|
+
'v',
|
|
124
|
+
'i',
|
|
125
|
+
's',
|
|
126
|
+
't',
|
|
127
|
+
'p',
|
|
128
|
+
'd',
|
|
129
|
+
'f',
|
|
130
|
+
'dt',
|
|
131
|
+
'et',
|
|
132
|
+
'kt',
|
|
133
|
+
'k',
|
|
134
|
+
'n',
|
|
135
|
+
'bt',
|
|
136
|
+
'b',
|
|
137
|
+
'c',
|
|
138
|
+
'ee',
|
|
139
|
+
'di',
|
|
140
|
+
'r',
|
|
141
|
+
];
|
|
142
|
+
/**
|
|
143
|
+
* Field labels for a reply event in V1 of the KERI protocol.
|
|
144
|
+
*/
|
|
145
|
+
export const RpyLabels = ['v', 't', 'd', 'dt', 'r', 'a'];
|
|
146
|
+
/**
|
|
147
|
+
* Full size of a CESR version string in bytes.
|
|
148
|
+
*/
|
|
149
|
+
export const VERFULLSIZE = 17;
|
|
150
|
+
/**
|
|
151
|
+
* Minimum number of bytes a CESR parser must sniff to receive the entire version string.
|
|
152
|
+
*/
|
|
153
|
+
export const MINSNIFFSIZE = 12 + VERFULLSIZE;
|
|
154
|
+
export const MINSIGSIZE = 4;
|
|
155
|
+
// const version_pattern = 'KERI(?P<major>[0-9a-f])(?P<minor>[0-9a-f])
|
|
156
|
+
// (?P<kind>[A-Z]{4})(?P<size>[0-9a-f]{6})'
|
|
157
|
+
// const version_pattern1 = `KERI\(\?P<major>\[0\-9a\-f\]\)\(\?P<minor>\[0\-9a\-f\]\)\
|
|
158
|
+
// (\?P<kind>\[A\-Z\]\{4\}\)\(\?P<size>\[0\-9a\-f\]\{6\}\)_`
|
|
159
|
+
/**
|
|
160
|
+
* Regular expression for a version 1 CESR object version string.
|
|
161
|
+
*/
|
|
162
|
+
export const VEREX = '(KERI|ACDC)([0-9a-f])([0-9a-f])([A-Z]{4})([0-9a-f]{6})_';
|
|
163
|
+
/**
|
|
164
|
+
* Parses a serialization version string into the protocol, protocol version, serialization type, and raw size.
|
|
165
|
+
* Uses regex matchers to validate and extract version string parts.
|
|
166
|
+
* @param {string} versionString version string
|
|
167
|
+
* @return {Object} tuple of prototol (KERI or ACDC), kind of serialization like cbor,json, or mgpk,
|
|
168
|
+
* protocol version, and raw size of serialization
|
|
169
|
+
*/
|
|
170
|
+
export function deversify(versionString) {
|
|
171
|
+
let kind;
|
|
172
|
+
let size;
|
|
173
|
+
let proto;
|
|
174
|
+
const version = Vrsn_1_0;
|
|
175
|
+
// we need to identify how to match the buffers pattern ,like we do regex matching for strings
|
|
176
|
+
const re = new RegExp(VEREX);
|
|
177
|
+
// Regex pattern matching
|
|
178
|
+
const match = re.exec(versionString);
|
|
179
|
+
if (match) {
|
|
180
|
+
[proto, version.major, version.minor, kind, size] = [
|
|
181
|
+
match[1],
|
|
182
|
+
+match[2],
|
|
183
|
+
+match[3],
|
|
184
|
+
match[4],
|
|
185
|
+
match[5],
|
|
186
|
+
];
|
|
187
|
+
if (!Object.values(Serials).includes(kind)) {
|
|
188
|
+
throw new Error(`Invalid serialization kind = ${kind}`);
|
|
189
|
+
}
|
|
190
|
+
if (!Object.values(Protocols).includes(proto)) {
|
|
191
|
+
throw new Error(`Invalid serialization kind = ${kind}`);
|
|
192
|
+
}
|
|
193
|
+
const ta = kind;
|
|
194
|
+
kind = Serials[ta];
|
|
195
|
+
const pa = proto;
|
|
196
|
+
proto = Protocols[pa];
|
|
197
|
+
return [proto, kind, version, size];
|
|
198
|
+
}
|
|
199
|
+
throw new Error(`Invalid version string = ${versionString}`);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Returns a valid KERI serialization version string specifying the protocol,
|
|
203
|
+
* protocol version, serialization type, and raw byte size of the serialization.
|
|
204
|
+
*
|
|
205
|
+
* Defaults to version 1.0.
|
|
206
|
+
* @param ident
|
|
207
|
+
* @param version
|
|
208
|
+
* @param kind
|
|
209
|
+
* @param size
|
|
210
|
+
*/
|
|
211
|
+
export function versify(ident = Protocols.KERI, version, kind = Serials.JSON, size = 0) {
|
|
212
|
+
version = version == undefined ? Vrsn_1_0 : version; // defaults to Version 1
|
|
213
|
+
const major = version.major.toString(16); // hex digits
|
|
214
|
+
const minor = version.minor.toString(16); // hex digits
|
|
215
|
+
// raw size in hex digits zero padded to 6 characters
|
|
216
|
+
const rawSize = size.toString(16).padStart(6, '0');
|
|
217
|
+
const terminationChar = '_'; // v1 termination character
|
|
218
|
+
return `${ident}${major}${minor}${kind}${rawSize}${terminationChar}`;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Map allowing lookup of Base64URLSafe characters by index.
|
|
222
|
+
*/
|
|
223
|
+
export const B64ChrByIdx = new Map([
|
|
224
|
+
[0, 'A'],
|
|
225
|
+
[1, 'B'],
|
|
226
|
+
[2, 'C'],
|
|
227
|
+
[3, 'D'],
|
|
228
|
+
[4, 'E'],
|
|
229
|
+
[5, 'F'],
|
|
230
|
+
[6, 'G'],
|
|
231
|
+
[7, 'H'],
|
|
232
|
+
[8, 'I'],
|
|
233
|
+
[9, 'J'],
|
|
234
|
+
[10, 'K'],
|
|
235
|
+
[11, 'L'],
|
|
236
|
+
[12, 'M'],
|
|
237
|
+
[13, 'N'],
|
|
238
|
+
[14, 'O'],
|
|
239
|
+
[15, 'P'],
|
|
240
|
+
[16, 'Q'],
|
|
241
|
+
[17, 'R'],
|
|
242
|
+
[18, 'S'],
|
|
243
|
+
[19, 'T'],
|
|
244
|
+
[20, 'U'],
|
|
245
|
+
[21, 'V'],
|
|
246
|
+
[22, 'W'],
|
|
247
|
+
[23, 'X'],
|
|
248
|
+
[24, 'Y'],
|
|
249
|
+
[25, 'Z'],
|
|
250
|
+
[26, 'a'],
|
|
251
|
+
[27, 'b'],
|
|
252
|
+
[28, 'c'],
|
|
253
|
+
[29, 'd'],
|
|
254
|
+
[30, 'e'],
|
|
255
|
+
[31, 'f'],
|
|
256
|
+
[32, 'g'],
|
|
257
|
+
[33, 'h'],
|
|
258
|
+
[34, 'i'],
|
|
259
|
+
[35, 'j'],
|
|
260
|
+
[36, 'k'],
|
|
261
|
+
[37, 'l'],
|
|
262
|
+
[38, 'm'],
|
|
263
|
+
[39, 'n'],
|
|
264
|
+
[40, 'o'],
|
|
265
|
+
[41, 'p'],
|
|
266
|
+
[42, 'q'],
|
|
267
|
+
[43, 'r'],
|
|
268
|
+
[44, 's'],
|
|
269
|
+
[45, 't'],
|
|
270
|
+
[46, 'u'],
|
|
271
|
+
[47, 'v'],
|
|
272
|
+
[48, 'w'],
|
|
273
|
+
[49, 'x'],
|
|
274
|
+
[50, 'y'],
|
|
275
|
+
[51, 'z'],
|
|
276
|
+
[52, '0'],
|
|
277
|
+
[53, '1'],
|
|
278
|
+
[54, '2'],
|
|
279
|
+
[55, '3'],
|
|
280
|
+
[56, '4'],
|
|
281
|
+
[57, '5'],
|
|
282
|
+
[58, '6'],
|
|
283
|
+
[59, '7'],
|
|
284
|
+
[60, '8'],
|
|
285
|
+
[61, '9'],
|
|
286
|
+
[62, '-'],
|
|
287
|
+
[63, '_'],
|
|
288
|
+
]);
|
|
289
|
+
/**
|
|
290
|
+
* Map allowing lookup of Base64URLSafe index by character.
|
|
291
|
+
*/
|
|
292
|
+
export const B64IdxByChr = new Map(Array.from(B64ChrByIdx, (entry) => [entry[1], entry[0]]));
|
|
293
|
+
/**
|
|
294
|
+
* Converts an integer to a Base64URLSafe encoded string, left padded as specified.
|
|
295
|
+
* @param i integer to convert
|
|
296
|
+
* @param l minimum length of Base64 digits left padded with Base64 0 == 'A' character.
|
|
297
|
+
*/
|
|
298
|
+
export function intToB64(i, l = 1) {
|
|
299
|
+
let out = '';
|
|
300
|
+
while (l != 0) {
|
|
301
|
+
out = B64ChrByIdx.get(i % 64) + out;
|
|
302
|
+
i = Math.floor(i / 64);
|
|
303
|
+
if (i == 0) {
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
const x = l - out.length;
|
|
308
|
+
for (let i = 0; i < x; i++) {
|
|
309
|
+
out = 'A' + out;
|
|
310
|
+
}
|
|
311
|
+
return out;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Converts an integer to a Base64URLSafe encoded string to a byte array, left padded as specified.
|
|
315
|
+
* @param i integer to convert
|
|
316
|
+
* @param l minimum length of Base64 digits left padded with Base64 0 == 'A' character.
|
|
317
|
+
*/
|
|
318
|
+
export function intToB64b(n, l = 1) {
|
|
319
|
+
const s = intToB64(n, l);
|
|
320
|
+
return b(s);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Converts a Base64URLSafe encoded string to an integer.
|
|
324
|
+
* @param s string to convert
|
|
325
|
+
*/
|
|
326
|
+
export function b64ToInt(s) {
|
|
327
|
+
if (s.length == 0) {
|
|
328
|
+
throw new Error('Empty string, conversion undefined.');
|
|
329
|
+
}
|
|
330
|
+
let i = 0;
|
|
331
|
+
const rev = s.split('').reverse();
|
|
332
|
+
rev.forEach((c, e) => {
|
|
333
|
+
i |= B64IdxByChr.get(c) << (e * 6);
|
|
334
|
+
});
|
|
335
|
+
return i;
|
|
336
|
+
}
|
|
337
|
+
// Built in encoder and decoder for converting to and from UTF-8 strings and Uint8Array byte arrays.
|
|
338
|
+
const encoder = new TextEncoder();
|
|
339
|
+
const decoder = new TextDecoder();
|
|
340
|
+
/**
|
|
341
|
+
* Converts a UTF-8 string to bytes.
|
|
342
|
+
* Output is an encoded array of bytes. Assumes UTF-8 encoding.
|
|
343
|
+
* @param s string to be encoded as an array of bytes
|
|
344
|
+
*/
|
|
345
|
+
export function b(s) {
|
|
346
|
+
return encoder.encode(s);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Convert bytes to UTF-8 string.
|
|
350
|
+
* @param u array of bytes to be converted to UTF-8 string.
|
|
351
|
+
*/
|
|
352
|
+
export function d(u) {
|
|
353
|
+
return decoder.decode(u);
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Concatenates two byte arrays together in a new byte array.
|
|
357
|
+
* @param one first byte array to be concatenated
|
|
358
|
+
* @param two second byte array to be concatenated
|
|
359
|
+
*/
|
|
360
|
+
export function concat(one, two) {
|
|
361
|
+
const out = new Uint8Array(one.length + two.length);
|
|
362
|
+
out.set(one);
|
|
363
|
+
out.set(two, one.length);
|
|
364
|
+
return out;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Converts a big-endian byte array into an integer.
|
|
368
|
+
*
|
|
369
|
+
* @param array - A `Uint8Array` of bytes representing a big-endian integer.
|
|
370
|
+
* @returns The integer represented by the byte array.
|
|
371
|
+
*
|
|
372
|
+
* Example:
|
|
373
|
+
* readInt(Uint8Array([0x01, 0x02, 0x03])) // returns 66051
|
|
374
|
+
*
|
|
375
|
+
* How it works:
|
|
376
|
+
* - The function interprets the array as a big-endian number.
|
|
377
|
+
* - Each byte is added to the integer after shifting the previous value left by 8 bits (multiplying by 256).
|
|
378
|
+
*/
|
|
379
|
+
export function readInt(array) {
|
|
380
|
+
let value = 0;
|
|
381
|
+
for (let i = 0; i < array.length; i++) {
|
|
382
|
+
value = value * 256 + array[i];
|
|
383
|
+
}
|
|
384
|
+
return value;
|
|
385
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Codex, Sizage } from './matter';
|
|
1
|
+
import { Codex, Sizage } from './matter.ts';
|
|
2
2
|
export interface CounterArgs {
|
|
3
3
|
code?: string;
|
|
4
4
|
count?: number;
|
|
@@ -35,7 +35,7 @@ export declare class Counter {
|
|
|
35
35
|
get code(): string;
|
|
36
36
|
get count(): number;
|
|
37
37
|
get qb64(): string;
|
|
38
|
-
get qb64b(): Uint8Array
|
|
38
|
+
get qb64b(): Uint8Array<ArrayBufferLike>;
|
|
39
39
|
countToB64(l?: number): string;
|
|
40
40
|
static semVerToB64(version?: string, major?: number, minor?: number, patch?: number): string;
|
|
41
41
|
private _infil;
|