saro-dat 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/crypto.d.ts +9 -4
- package/dist/crypto.d.ts.map +1 -1
- package/dist/crypto.js +34 -26
- package/dist/crypto.js.map +1 -1
- package/dist/dat.bank.d.ts +3 -4
- package/dist/dat.bank.d.ts.map +1 -1
- package/dist/dat.bank.js +17 -23
- package/dist/dat.bank.js.map +1 -1
- package/dist/dat.d.ts +22 -0
- package/dist/dat.d.ts.map +1 -0
- package/dist/dat.js +51 -0
- package/dist/dat.js.map +1 -0
- package/dist/dat.key.d.ts +5 -6
- package/dist/dat.key.d.ts.map +1 -1
- package/dist/dat.key.js +28 -33
- package/dist/dat.key.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/signature.d.ts +10 -4
- package/dist/signature.d.ts.map +1 -1
- package/dist/signature.js +119 -94
- package/dist/signature.js.map +1 -1
- package/dist/util.base64.d.ts +6 -0
- package/dist/util.base64.d.ts.map +1 -0
- package/dist/util.base64.js +29 -0
- package/dist/util.base64.js.map +1 -0
- package/dist/util.bytes.d.ts +17 -0
- package/dist/util.bytes.d.ts.map +1 -0
- package/dist/util.bytes.js +86 -0
- package/dist/util.bytes.js.map +1 -0
- package/dist/util.hex.d.ts +3 -0
- package/dist/util.hex.d.ts.map +1 -0
- package/dist/util.hex.js +14 -0
- package/dist/util.hex.js.map +1 -0
- package/dist/util.misc.d.ts +4 -0
- package/dist/util.misc.d.ts.map +1 -0
- package/dist/util.misc.js +22 -0
- package/dist/util.misc.js.map +1 -0
- package/package.json +3 -3
- package/dist/util.d.ts +0 -30
- package/dist/util.d.ts.map +0 -1
- package/dist/util.js +0 -110
- package/dist/util.js.map +0 -1
package/dist/crypto.d.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
export type DatCryptoAlgorithm = "AES128GCMN" | "AES256GCMN";
|
|
2
|
+
type CryptoConfig = {
|
|
3
|
+
name: string;
|
|
4
|
+
length: number;
|
|
5
|
+
};
|
|
2
6
|
export declare class DatCryptoKey {
|
|
3
7
|
private readonly config;
|
|
4
8
|
readonly algorithm: DatCryptoAlgorithm;
|
|
5
9
|
readonly key: CryptoKey;
|
|
6
|
-
constructor(algorithm: DatCryptoAlgorithm, key: CryptoKey);
|
|
10
|
+
constructor(algorithm: DatCryptoAlgorithm, key: CryptoKey, config?: CryptoConfig);
|
|
7
11
|
static generate(algorithm: DatCryptoAlgorithm): Promise<DatCryptoKey>;
|
|
8
|
-
static imports(
|
|
12
|
+
static imports(algorithm: string, base64: string): Promise<DatCryptoKey>;
|
|
9
13
|
exports(): Promise<string>;
|
|
10
|
-
encrypt(data:
|
|
11
|
-
decrypt(data:
|
|
14
|
+
encrypt(data: any): Promise<ArrayBuffer>;
|
|
15
|
+
decrypt(data: any): Promise<ArrayBuffer>;
|
|
12
16
|
}
|
|
17
|
+
export {};
|
|
13
18
|
//# sourceMappingURL=crypto.d.ts.map
|
package/dist/crypto.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,YAAY,CAAC;AAE7D,KAAK,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAmBrD,qBAAa,YAAY;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,SAAgB,SAAS,EAAE,kBAAkB,CAAC;IAC9C,SAAgB,GAAG,EAAE,SAAS,CAAC;gBAG3B,SAAS,EAAE,kBAAkB,EAC7B,GAAG,EAAE,SAAS,EACd,MAAM,GAAE,YAAyC;WAOxC,QAAQ,CAAC,SAAS,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;WAQ9D,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IASxE,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAI1B,OAAO,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC;IAgBxC,OAAO,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC;CAoBjD"}
|
package/dist/crypto.js
CHANGED
|
@@ -1,55 +1,63 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const algorithms = ["AES128GCMN", "AES256GCMN"];
|
|
1
|
+
import { concatArrayBuffer, toArrayBuffer, toArrayBufferFromBase64Url, toBase64Url } from "./index.js";
|
|
3
2
|
const CRYPTO_CONFIG = {
|
|
4
|
-
AES128GCMN: { name: "AES-GCM", length: 128 },
|
|
5
|
-
AES256GCMN: { name: "AES-GCM", length: 256 },
|
|
3
|
+
"AES128GCMN": { name: "AES-GCM", length: 128 },
|
|
4
|
+
"AES256GCMN": { name: "AES-GCM", length: 256 },
|
|
6
5
|
};
|
|
6
|
+
function unsupportedAlgorithm(algorithm) {
|
|
7
|
+
return new Error(`Unsupported DAT Crypto Algorithm: ${algorithm}`);
|
|
8
|
+
}
|
|
9
|
+
function getCryptoConfig(algorithm) {
|
|
10
|
+
const config = CRYPTO_CONFIG[algorithm];
|
|
11
|
+
if (config) {
|
|
12
|
+
return config;
|
|
13
|
+
}
|
|
14
|
+
throw unsupportedAlgorithm(algorithm);
|
|
15
|
+
}
|
|
7
16
|
export class DatCryptoKey {
|
|
8
17
|
config;
|
|
9
18
|
algorithm;
|
|
10
19
|
key;
|
|
11
|
-
constructor(algorithm, key) {
|
|
20
|
+
constructor(algorithm, key, config = getCryptoConfig(algorithm)) {
|
|
12
21
|
this.algorithm = algorithm;
|
|
13
22
|
this.key = key;
|
|
14
|
-
this.config =
|
|
23
|
+
this.config = config;
|
|
15
24
|
}
|
|
16
25
|
static async generate(algorithm) {
|
|
17
|
-
const config =
|
|
18
|
-
if (!config)
|
|
19
|
-
throw new Error(`Unsupported algorithm: ${algorithm}`);
|
|
26
|
+
const config = getCryptoConfig(algorithm);
|
|
20
27
|
const key = await crypto.subtle.generateKey({ name: config.name, length: config.length }, true, ["encrypt", "decrypt"]);
|
|
21
|
-
return new DatCryptoKey(algorithm, key);
|
|
28
|
+
return new DatCryptoKey(algorithm, key, config);
|
|
22
29
|
}
|
|
23
|
-
static async imports(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
const algorithm = algorithmString;
|
|
28
|
-
const config = CRYPTO_CONFIG[algorithm];
|
|
29
|
-
if (!config)
|
|
30
|
-
throw new Error(`Unsupported algorithm: ${algorithm}`);
|
|
31
|
-
const bytes = new Uint8Array(decodeBase64(base64));
|
|
30
|
+
static async imports(algorithm, base64) {
|
|
31
|
+
const config = getCryptoConfig(algorithm);
|
|
32
|
+
const bytes = toArrayBufferFromBase64Url(base64);
|
|
32
33
|
const key = await crypto.subtle.importKey("raw", bytes, { name: config.name }, true, ["encrypt", "decrypt"]);
|
|
33
|
-
return new DatCryptoKey(algorithm, key);
|
|
34
|
+
return new DatCryptoKey(algorithm, key, config);
|
|
34
35
|
}
|
|
35
36
|
async exports() {
|
|
36
|
-
return
|
|
37
|
+
return toBase64Url(await crypto.subtle.exportKey("raw", this.key));
|
|
37
38
|
}
|
|
38
39
|
async encrypt(data) {
|
|
40
|
+
data = toArrayBuffer(data);
|
|
39
41
|
if (!data.byteLength) {
|
|
40
|
-
return
|
|
42
|
+
return data;
|
|
41
43
|
}
|
|
42
44
|
if (this.config.name == "AES-GCM") {
|
|
43
45
|
const nonce = new Uint8Array(12);
|
|
44
46
|
crypto.getRandomValues(nonce);
|
|
45
47
|
const encrypt = await crypto.subtle.encrypt({ name: this.config.name, iv: nonce }, this.key, data);
|
|
46
|
-
return
|
|
48
|
+
return concatArrayBuffer(nonce, encrypt);
|
|
47
49
|
}
|
|
48
|
-
throw
|
|
50
|
+
throw unsupportedAlgorithm(this.algorithm);
|
|
49
51
|
}
|
|
50
52
|
async decrypt(data) {
|
|
53
|
+
if (typeof data == "string") {
|
|
54
|
+
data = toArrayBufferFromBase64Url(data);
|
|
55
|
+
}
|
|
56
|
+
else if (!(data instanceof ArrayBuffer)) {
|
|
57
|
+
data = toArrayBuffer(data);
|
|
58
|
+
}
|
|
51
59
|
if (!data.byteLength) {
|
|
52
|
-
return
|
|
60
|
+
return data;
|
|
53
61
|
}
|
|
54
62
|
if (this.config.name == "AES-GCM") {
|
|
55
63
|
if (data.byteLength <= 12) {
|
|
@@ -58,7 +66,7 @@ export class DatCryptoKey {
|
|
|
58
66
|
const nonce = data.slice(0, 12);
|
|
59
67
|
return await crypto.subtle.decrypt({ name: this.config.name, iv: nonce }, this.key, data.slice(12));
|
|
60
68
|
}
|
|
61
|
-
throw
|
|
69
|
+
throw unsupportedAlgorithm(this.algorithm);
|
|
62
70
|
}
|
|
63
71
|
}
|
|
64
72
|
//# sourceMappingURL=crypto.js.map
|
package/dist/crypto.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAE,aAAa,EAAE,0BAA0B,EAAE,WAAW,EAAC,MAAM,YAAY,CAAC;AAMrG,MAAM,aAAa,GAAiC;IAChD,YAAY,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE;IAC9C,YAAY,EAAE,EAAE,IAAI,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CAAC;aAAM,IAAI,CAAC,CAAC,IAAI,YAAY,WAAW,CAAC,EAAE,CAAC;YACxC,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,CAAA;QAC9B,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACnB,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,SAAS,EAAE,CAAC;YAChC,IAAI,IAAI,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;gBACxB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;YAC3C,CAAC;YACD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAChC,OAAO,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAC9B,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAClE,CAAC;QACN,CAAC;QACD,MAAM,oBAAoB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC/C,CAAC;CACJ"}
|
package/dist/dat.bank.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DatKey, DatPayload,
|
|
1
|
+
import { DatKey, DatPayload, DatSignatureKeyOutOption } from "./index.js";
|
|
2
2
|
export declare class DatBank {
|
|
3
3
|
private readonly issueKey;
|
|
4
4
|
private readonly verifyKeys;
|
|
@@ -6,8 +6,7 @@ export declare class DatBank {
|
|
|
6
6
|
static imports(format: string): Promise<DatBank>;
|
|
7
7
|
exports(datSignatureKeyOutOption: DatSignatureKeyOutOption): Promise<string>;
|
|
8
8
|
find(kid: string): DatKey | null;
|
|
9
|
-
toDat(plain:
|
|
10
|
-
|
|
11
|
-
toPayload(dat: string): Promise<DatPayload>;
|
|
9
|
+
toDat(plain: any, secure: any): Promise<string>;
|
|
10
|
+
toPayload(dat: any): Promise<DatPayload>;
|
|
12
11
|
}
|
|
13
12
|
//# sourceMappingURL=dat.bank.d.ts.map
|
package/dist/dat.bank.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dat.bank.d.ts","sourceRoot":"","sources":["../src/dat.bank.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"dat.bank.d.ts","sourceRoot":"","sources":["../src/dat.bank.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAY,UAAU,EAAE,wBAAwB,EAAc,MAAM,YAAY,CAAC;AAE/F,qBAAa,OAAO;IAChB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;IACzC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAW;gBAE1B,QAAQ,GAAE,MAAM,GAAG,IAAW,EAAE,UAAU,GAAE,MAAM,EAAO;WAKxD,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAoBhD,OAAO,CAAC,wBAAwB,EAAE,wBAAwB,GAAG,OAAO,CAAC,MAAM,CAAC;IAIlF,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAI1B,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAO/C,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC;CAWjD"}
|
package/dist/dat.bank.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DatKey,
|
|
1
|
+
import { DatKey, DatParts, nowUnixtime } from "./index.js";
|
|
2
2
|
export class DatBank {
|
|
3
3
|
issueKey;
|
|
4
4
|
verifyKeys;
|
|
@@ -7,48 +7,42 @@ export class DatBank {
|
|
|
7
7
|
this.verifyKeys = verifyKeys;
|
|
8
8
|
}
|
|
9
9
|
static async imports(format) {
|
|
10
|
-
const now =
|
|
10
|
+
const now = nowUnixtime();
|
|
11
11
|
const lines = format.split('\n').map(e => e.trim()).filter(e => !!e);
|
|
12
12
|
let keys = [];
|
|
13
13
|
for (const line of lines) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const key = await DatKey.imports(line);
|
|
15
|
+
if (keys.find(e => e.kid === key.kid)) {
|
|
16
|
+
return Promise.reject(new Error(`Invalid DAT KEYS - Duplicate KID ${key.kid}`));
|
|
17
|
+
}
|
|
18
|
+
keys.push(key);
|
|
18
19
|
}
|
|
19
20
|
keys.sort((a, b) => a.issueBegin - b.issueBegin);
|
|
20
21
|
const issueKey = keys.findLast(e => e.hasSigningKey() && e.issueBegin <= now && e.issueEnd > now) || null;
|
|
21
22
|
return new DatBank(issueKey, keys);
|
|
22
23
|
}
|
|
23
24
|
async exports(datSignatureKeyOutOption) {
|
|
24
|
-
|
|
25
|
-
for (const key of this.verifyKeys) {
|
|
26
|
-
lines.push(await key.export(datSignatureKeyOutOption));
|
|
27
|
-
}
|
|
28
|
-
return lines.join('\n');
|
|
25
|
+
return (await Promise.all(this.verifyKeys.map(e => e.exports(datSignatureKeyOutOption)))).join('\n');
|
|
29
26
|
}
|
|
30
27
|
find(kid) {
|
|
31
28
|
return this.verifyKeys.find(e => e.kid === kid) || null;
|
|
32
29
|
}
|
|
33
30
|
async toDat(plain, secure) {
|
|
34
31
|
if (this.issueKey) {
|
|
35
|
-
return await this.issueKey.toDat(
|
|
32
|
+
return await this.issueKey.toDat(plain, secure);
|
|
36
33
|
}
|
|
37
|
-
throw new Error("
|
|
34
|
+
throw new Error("Invalid DAT: Signing Key Does Not Exist");
|
|
38
35
|
}
|
|
39
|
-
async
|
|
40
|
-
const parts =
|
|
41
|
-
if (parts.
|
|
42
|
-
return Promise.reject("
|
|
36
|
+
async toPayload(dat) {
|
|
37
|
+
const parts = DatParts.from(dat);
|
|
38
|
+
if (parts.errorFormat) {
|
|
39
|
+
return Promise.reject("Invalid DAT: Format");
|
|
43
40
|
}
|
|
44
|
-
const key = this.find(parts.kid);
|
|
41
|
+
const key = parts.errorFormat ? null : this.find(parts.kid);
|
|
45
42
|
if (key != null) {
|
|
46
|
-
return key.
|
|
43
|
+
return key.toPayload(parts);
|
|
47
44
|
}
|
|
48
|
-
return Promise.reject("
|
|
49
|
-
}
|
|
50
|
-
async toPayload(dat) {
|
|
51
|
-
return this.toPayloadBuffer(dat).then(serializePayload);
|
|
45
|
+
return Promise.reject("Invalid DAT: KID Not Found");
|
|
52
46
|
}
|
|
53
47
|
}
|
|
54
48
|
//# sourceMappingURL=dat.bank.js.map
|
package/dist/dat.bank.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dat.bank.js","sourceRoot":"","sources":["../src/dat.bank.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"dat.bank.js","sourceRoot":"","sources":["../src/dat.bank.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,QAAQ,EAAwC,WAAW,EAAC,MAAM,YAAY,CAAC;AAE/F,MAAM,OAAO,OAAO;IACC,QAAQ,CAAgB;IACxB,UAAU,CAAW;IAEtC,YAAY,WAA0B,IAAI,EAAE,aAAuB,EAAE;QACjE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,MAAc;QAC/B,MAAM,GAAG,GAAG,WAAW,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACrE,IAAI,I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CAAC;IAC5D,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,KAAU,EAAE,MAAW;QAC/B,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChB,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACpD,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC/D,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,GAAQ;QACpB,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;YACpB,OAAO,OAAO,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;QACjD,CAAC;QACD,MAAM,GAAG,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC5D,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;YACd,OAAO,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAChC,CAAC;QACD,OAAO,OAAO,CAAC,MAAM,CAAC,4BAA4B,CAAC,CAAC;IACxD,CAAC;CACJ"}
|
package/dist/dat.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare class DatParts {
|
|
2
|
+
readonly errorFormat: boolean;
|
|
3
|
+
readonly dat: string;
|
|
4
|
+
readonly expire: number;
|
|
5
|
+
readonly kid: string;
|
|
6
|
+
readonly plain: string;
|
|
7
|
+
readonly secure: string;
|
|
8
|
+
readonly signature: string;
|
|
9
|
+
constructor(dat: string);
|
|
10
|
+
static from(dat: string | undefined | null | DatParts): DatParts;
|
|
11
|
+
expired(): boolean;
|
|
12
|
+
body(): string;
|
|
13
|
+
}
|
|
14
|
+
export declare class DatPayload {
|
|
15
|
+
readonly expire: number;
|
|
16
|
+
readonly plainBytes: ArrayBuffer;
|
|
17
|
+
readonly secureBytes: ArrayBuffer;
|
|
18
|
+
constructor(expire: number, plain: ArrayBuffer, secure: ArrayBuffer);
|
|
19
|
+
get plain(): string;
|
|
20
|
+
get secure(): string;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=dat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dat.d.ts","sourceRoot":"","sources":["../src/dat.ts"],"names":[],"mappings":"AAGA,qBAAa,QAAQ;IACjB,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAQ;IACrC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAK;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAM;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAM;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAM;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAM;gBAEpB,GAAG,EAAE,MAAM;IAYvB,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,GAAC,SAAS,GAAC,IAAI,GAAC,QAAQ,GAAG,QAAQ;IAO1D,OAAO,IAAI,OAAO;IAIlB,IAAI,IAAI,MAAM;CAGjB;AAED,qBAAa,UAAU;IACnB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC;IACjC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;gBAEtB,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW;IAMnE,IAAI,KAAK,IAAI,MAAM,CAElB;IACD,IAAI,MAAM,IAAI,MAAM,CAEnB;CACJ"}
|
package/dist/dat.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { nowUnixtime, toSafeIntegerOrNaN } from "./util.misc";
|
|
2
|
+
import { toUtf8FromBase64Url } from "./util.base64";
|
|
3
|
+
export class DatParts {
|
|
4
|
+
errorFormat = true;
|
|
5
|
+
dat;
|
|
6
|
+
expire = 0;
|
|
7
|
+
kid = '';
|
|
8
|
+
plain = '';
|
|
9
|
+
secure = '';
|
|
10
|
+
signature = '';
|
|
11
|
+
constructor(dat) {
|
|
12
|
+
const parts = (this.dat = dat || '').split('.');
|
|
13
|
+
if (dat && parts.length == 5) {
|
|
14
|
+
this.expire = toSafeIntegerOrNaN(parts[0]);
|
|
15
|
+
this.kid = parts[1];
|
|
16
|
+
this.plain = parts[2];
|
|
17
|
+
this.secure = parts[3];
|
|
18
|
+
this.signature = parts[4];
|
|
19
|
+
this.errorFormat = !(this.signature && this.expire > 0);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
static from(dat) {
|
|
23
|
+
if (dat instanceof DatParts) {
|
|
24
|
+
return dat;
|
|
25
|
+
}
|
|
26
|
+
return new DatParts(dat || '');
|
|
27
|
+
}
|
|
28
|
+
expired() {
|
|
29
|
+
return this.errorFormat || this.expire < nowUnixtime();
|
|
30
|
+
}
|
|
31
|
+
body() {
|
|
32
|
+
return this.dat.substring(0, this.dat.lastIndexOf('.'));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class DatPayload {
|
|
36
|
+
expire;
|
|
37
|
+
plainBytes;
|
|
38
|
+
secureBytes;
|
|
39
|
+
constructor(expire, plain, secure) {
|
|
40
|
+
this.expire = expire;
|
|
41
|
+
this.plainBytes = plain;
|
|
42
|
+
this.secureBytes = secure;
|
|
43
|
+
}
|
|
44
|
+
get plain() {
|
|
45
|
+
return toUtf8FromBase64Url(this.plainBytes);
|
|
46
|
+
}
|
|
47
|
+
get secure() {
|
|
48
|
+
return toUtf8FromBase64Url(this.secureBytes);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=dat.js.map
|
package/dist/dat.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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CAAC;IAED,OAAO;QACH,OAAO,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,MAAM,GAAG,WAAW,EAAE,CAAC;IAC3D,CAAC;IAED,IAAI;QACA,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5D,CAAC;CACJ;AAED,MAAM,OAAO,UAAU;IACV,MAAM,CAAS;IACf,UAAU,CAAc;IACxB,WAAW,CAAc;IAElC,YAAY,MAAc,EAAE,KAAkB,EAAE,MAAmB;QAC/D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QACxB,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC;IAC9B,CAAC;IAED,IAAI,KAAK;QACL,OAAO,mBAAmB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAChD,CAAC;IACD,IAAI,MAAM;QACN,OAAO,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACjD,CAAC;CACJ"}
|
package/dist/dat.key.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DatCryptoKey,
|
|
1
|
+
import { DatCryptoKey, DatPayload, DatSignatureKey, type DatSignatureKeyOutOption } from "./index.js";
|
|
2
2
|
export declare class DatKey {
|
|
3
3
|
readonly kid: string;
|
|
4
4
|
readonly signatureKey: DatSignatureKey;
|
|
@@ -7,12 +7,11 @@ export declare class DatKey {
|
|
|
7
7
|
readonly issueEnd: number;
|
|
8
8
|
readonly tokenTtl: number;
|
|
9
9
|
constructor(kid: string, signatureKey: DatSignatureKey, cryptoKey: DatCryptoKey, issueBegin: number, issueEnd: number, tokenTtl: number);
|
|
10
|
-
|
|
11
|
-
static
|
|
10
|
+
exports(datSignatureKeyOutOption: DatSignatureKeyOutOption): Promise<string>;
|
|
11
|
+
static imports(format: string): Promise<DatKey>;
|
|
12
12
|
private static _import_ver_2;
|
|
13
|
-
toDat(
|
|
14
|
-
toPayload(
|
|
15
|
-
toPayloadBuffer(parts: DatParts | string): Promise<DatPayloadBuffer>;
|
|
13
|
+
toDat(plain: any, secure: any): Promise<string>;
|
|
14
|
+
toPayload(dat: any): Promise<DatPayload>;
|
|
16
15
|
hasSigningKey(): boolean;
|
|
17
16
|
}
|
|
18
17
|
//# sourceMappingURL=dat.key.d.ts.map
|
package/dist/dat.key.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dat.key.d.ts","sourceRoot":"","sources":["../src/dat.key.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,YAAY,
|
|
1
|
+
{"version":3,"file":"dat.key.d.ts","sourceRoot":"","sources":["../src/dat.key.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,YAAY,EAEZ,UAAU,EACV,eAAe,EACf,KAAK,wBAAwB,EAIhC,MAAM,YAAY,CAAC;AAEpB,qBAAa,MAAM;IACf,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAgB,YAAY,EAAE,eAAe,CAAC;IAC9C,SAAgB,SAAS,EAAE,YAAY,CAAC;IACxC,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,QAAQ,EAAE,MAAM,CAAC;gBAG7B,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,eAAe,EAC7B,SAAS,EAAE,YAAY,EACvB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM;IAsBd,OAAO,CAAC,wBAAwB,EAAE,wBAAwB,GAAG,OAAO,CAAC,MAAM,CAAC;WAYrE,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;mBAWhC,aAAa;IAU5B,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAW/C,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC;IAiB9C,aAAa,IAAI,OAAO;CAG3B"}
|
package/dist/dat.key.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { DAT_VERSION, DatCryptoKey, DatSignatureKey,
|
|
2
|
-
import { Buffer } from "buffer";
|
|
1
|
+
import { DAT_VERSION, DatCryptoKey, DatParts, DatPayload, DatSignatureKey, toBase64Url, toArrayBuffer, isIntegerRanged, nowUnixtime, toArrayBufferFromBase64Url } from "./index.js";
|
|
3
2
|
export class DatKey {
|
|
4
3
|
kid;
|
|
5
4
|
signatureKey;
|
|
@@ -9,10 +8,16 @@ export class DatKey {
|
|
|
9
8
|
tokenTtl;
|
|
10
9
|
constructor(kid, signatureKey, cryptoKey, issueBegin, issueEnd, tokenTtl) {
|
|
11
10
|
if (kid.match(/[.\r\n]/) != null) {
|
|
12
|
-
throw new Error(`Invalid
|
|
11
|
+
throw new Error(`Invalid Kid: kid is not allowed ".", "\\r", "\\n"" ${kid}`);
|
|
13
12
|
}
|
|
14
|
-
if (
|
|
15
|
-
throw new Error(`Invalid issueBegin
|
|
13
|
+
if (!isIntegerRanged(issueBegin, 0)) {
|
|
14
|
+
throw new Error(`Invalid issueBegin: issueBegin is positive int or 0 ${issueBegin}`);
|
|
15
|
+
}
|
|
16
|
+
if (!isIntegerRanged(issueEnd, 0)) {
|
|
17
|
+
throw new Error(`Invalid issueEnd: issueEnd is positive int or 0 ${issueEnd}`);
|
|
18
|
+
}
|
|
19
|
+
if (!isIntegerRanged(tokenTtl, 1)) {
|
|
20
|
+
throw new Error(`Invalid tokenTtl: tokenTtl is positive int ${tokenTtl}`);
|
|
16
21
|
}
|
|
17
22
|
this.kid = kid;
|
|
18
23
|
this.signatureKey = signatureKey;
|
|
@@ -21,7 +26,7 @@ export class DatKey {
|
|
|
21
26
|
this.issueEnd = Math.floor(issueEnd);
|
|
22
27
|
this.tokenTtl = Math.floor(tokenTtl);
|
|
23
28
|
}
|
|
24
|
-
async
|
|
29
|
+
async exports(datSignatureKeyOutOption) {
|
|
25
30
|
const kid = this.kid;
|
|
26
31
|
const signAlg = this.signatureKey.algorithm;
|
|
27
32
|
const signKey = await this.signatureKey.exports(datSignatureKeyOutOption);
|
|
@@ -32,7 +37,7 @@ export class DatKey {
|
|
|
32
37
|
const tokenTtl = this.tokenTtl;
|
|
33
38
|
return `${DAT_VERSION}.${kid}.${signAlg}.${signKey}.${cryptoAlg}.${cryptoKey}.${issueBegin}.${issueEnd}.${tokenTtl}`;
|
|
34
39
|
}
|
|
35
|
-
static async
|
|
40
|
+
static async imports(format) {
|
|
36
41
|
const split = format.split(".");
|
|
37
42
|
switch (split[0] || '0') {
|
|
38
43
|
case '2':
|
|
@@ -52,40 +57,30 @@ export class DatKey {
|
|
|
52
57
|
const tokenTtl = Number(split[8]);
|
|
53
58
|
return new DatKey(kid, signKey, cryptoKey, issueBegin, issueEnd, tokenTtl);
|
|
54
59
|
}
|
|
55
|
-
async toDat(
|
|
56
|
-
const now =
|
|
60
|
+
async toDat(plain, secure) {
|
|
61
|
+
const now = nowUnixtime();
|
|
57
62
|
const exp = now + this.tokenTtl;
|
|
58
63
|
const kid = this.kid;
|
|
59
|
-
|
|
60
|
-
|
|
64
|
+
plain = toBase64Url(plain);
|
|
65
|
+
secure = toBase64Url(await this.cryptoKey.encrypt(toArrayBuffer(secure)));
|
|
61
66
|
const body = `${exp}.${kid}.${plain}.${secure}`;
|
|
62
|
-
const sign =
|
|
67
|
+
const sign = toBase64Url(await this.signatureKey.sign(body));
|
|
63
68
|
return `${body}.${sign}`;
|
|
64
69
|
}
|
|
65
|
-
async toPayload(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (typeof parts === 'string') {
|
|
70
|
-
parts = splitDat(parts);
|
|
71
|
-
}
|
|
72
|
-
if (parts.error) {
|
|
73
|
-
return Promise.reject("invalid format");
|
|
74
|
-
}
|
|
75
|
-
const exp = parts.expire;
|
|
76
|
-
if (exp < (new Date().getTime() / 1000)) {
|
|
77
|
-
return Promise.reject('expired');
|
|
70
|
+
async toPayload(dat) {
|
|
71
|
+
const parts = DatParts.from(dat);
|
|
72
|
+
if (parts.errorFormat) {
|
|
73
|
+
return Promise.reject("Invalid DAT: Format");
|
|
78
74
|
}
|
|
79
|
-
if (parts.
|
|
80
|
-
return Promise.reject(
|
|
75
|
+
if (parts.expired()) {
|
|
76
|
+
return Promise.reject("Invalid DAT: Expired");
|
|
81
77
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return Promise.reject('invalid signature');
|
|
78
|
+
if (!await this.signatureKey.verify(parts.body(), parts.signature)) {
|
|
79
|
+
return Promise.reject('Invalid DAT: Signature');
|
|
85
80
|
}
|
|
86
|
-
const plain =
|
|
87
|
-
const secure =
|
|
88
|
-
return (
|
|
81
|
+
const plain = toArrayBufferFromBase64Url(parts.plain);
|
|
82
|
+
const secure = await this.cryptoKey.decrypt(parts.secure);
|
|
83
|
+
return new DatPayload(parts.expire, plain, secure);
|
|
89
84
|
}
|
|
90
85
|
hasSigningKey() {
|
|
91
86
|
return this.signatureKey.hasSigningKey();
|
package/dist/dat.key.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dat.key.js","sourceRoot":"","sources":["../src/dat.key.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,YAAY,
|
|
1
|
+
{"version":3,"file":"dat.key.js","sourceRoot":"","sources":["../src/dat.key.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,eAAe,EAEf,WAAW,EACX,aAAa,EAAE,eAAe,EAAE,WAAW,EAC3C,0BAA0B,EAC7B,MAAM,YAAY,CAAC;AAEpB,MAAM,OAAO,MAAM;IACC,GAAG,CAAS;IACZ,YAAY,CAAkB;IAC9B,SAAS,CAAe;IACxB,UAAU,CAAS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AAE,CAAC;YAClB,OAAO,OAAO,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC;QAClD,CAAC;QACD,IAAI,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;YACjE,OAAO,OAAO,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC;QACpD,CAAC;QACD,MAAM,KAAK,GAAG,0BAA0B,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACtD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAE1D,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;IACtD,CAAC;IAED,aAAa;QACT,OAAO,IAAI,CAAC,YAAY,CAAC,aAAa,EAAE,CAAC;IAC7C,CAAC;CACJ"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
export declare const DAT_VERSION = "2";
|
|
2
|
+
export * from './dat.js';
|
|
2
3
|
export * from "./crypto.js";
|
|
3
4
|
export * from "./dat.key.js";
|
|
4
5
|
export * from "./dat.bank.js";
|
|
5
6
|
export * from "./signature.js";
|
|
6
|
-
export * from "./util.js";
|
|
7
|
+
export * from "./util.bytes.js";
|
|
8
|
+
export * from "./util.base64.js";
|
|
9
|
+
export * from "./util.hex.js";
|
|
10
|
+
export * from "./util.misc.js";
|
|
7
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,MAAM,CAAC;AAE/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,MAAM,CAAC;AAE/B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
export const DAT_VERSION = "2";
|
|
2
|
+
export * from './dat.js';
|
|
2
3
|
export * from "./crypto.js";
|
|
3
4
|
export * from "./dat.key.js";
|
|
4
5
|
export * from "./dat.bank.js";
|
|
5
6
|
export * from "./signature.js";
|
|
6
|
-
export * from "./util.js";
|
|
7
|
+
export * from "./util.bytes.js";
|
|
8
|
+
export * from "./util.base64.js";
|
|
9
|
+
export * from "./util.hex.js";
|
|
10
|
+
export * from "./util.misc.js";
|
|
7
11
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAC;AAE/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAC;AAE/B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC"}
|
package/dist/signature.d.ts
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
export type DatSignatureAlgorithm = "P256" | "P384" | "P521";
|
|
2
2
|
export type DatSignatureKeyOutOption = "FULL" | "SIGNING" | "VERIFYING";
|
|
3
|
+
type SignatureConfig = {
|
|
4
|
+
name: string;
|
|
5
|
+
curve: string;
|
|
6
|
+
hash: string;
|
|
7
|
+
};
|
|
3
8
|
export declare class DatSignatureKey {
|
|
4
9
|
private readonly config;
|
|
5
10
|
readonly algorithm: DatSignatureAlgorithm;
|
|
6
11
|
private readonly signingKey;
|
|
7
12
|
private readonly verifyingKey;
|
|
8
|
-
constructor(algorithm: DatSignatureAlgorithm, SigningKey: CryptoKey | null, VerifyingKey: CryptoKey);
|
|
13
|
+
constructor(algorithm: DatSignatureAlgorithm, SigningKey: CryptoKey | null, VerifyingKey: CryptoKey, config?: SignatureConfig);
|
|
9
14
|
static generate(algorithm: DatSignatureAlgorithm): Promise<DatSignatureKey>;
|
|
10
|
-
static imports(
|
|
15
|
+
static imports(algorithm: string, format: string): Promise<DatSignatureKey>;
|
|
11
16
|
exports(option: DatSignatureKeyOutOption): Promise<string>;
|
|
12
|
-
sign(
|
|
13
|
-
verify(body:
|
|
17
|
+
sign(body: any): Promise<ArrayBuffer>;
|
|
18
|
+
verify(body: any, signature: any): Promise<boolean>;
|
|
14
19
|
hasSigningKey(): boolean;
|
|
15
20
|
}
|
|
21
|
+
export {};
|
|
16
22
|
//# sourceMappingURL=signature.d.ts.map
|
package/dist/signature.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../src/signature.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../src/signature.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAC7D,MAAM,MAAM,wBAAwB,GAAG,MAAM,GAAG,SAAS,GAAG,WAAW,CAAC;AAExE,KAAK,eAAe,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AA+CrE,qBAAa,eAAe;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IACzC,SAAgB,SAAS,EAAE,qBAAqB,CAAC;IACjD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAY;gBAGrC,SAAS,EAAE,qBAAqB,EAChC,UAAU,EAAE,SAAS,GAAG,IAAI,EAC5B,YAAY,EAAE,SAAS,EACvB,MAAM,GAAE,eAA4C;WAQ3C,QAAQ,CAAC,SAAS,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC;WASpE,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IA6B3E,OAAO,CAAC,MAAM,EAAE,wBAAwB,GAAG,OAAO,CAAC,MAAM,CAAC;IAiB1D,IAAI,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC;IAarC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;IAmBzD,aAAa,IAAI,OAAO;CAG3B"}
|