@kya-os/mcp 1.2.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/CHANGELOG.md +64 -0
- package/LICENSE +21 -0
- package/README.md +135 -0
- package/dist/auth/handshake.d.ts +119 -0
- package/dist/auth/handshake.d.ts.map +1 -0
- package/dist/auth/handshake.js +267 -0
- package/dist/auth/handshake.js.map +1 -0
- package/dist/auth/index.d.ts +3 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +2 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/types.d.ts +31 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +7 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/delegation/audience-validator.d.ts +9 -0
- package/dist/delegation/audience-validator.d.ts.map +1 -0
- package/dist/delegation/audience-validator.js +17 -0
- package/dist/delegation/audience-validator.js.map +1 -0
- package/dist/delegation/bitstring.d.ts +37 -0
- package/dist/delegation/bitstring.d.ts.map +1 -0
- package/dist/delegation/bitstring.js +117 -0
- package/dist/delegation/bitstring.js.map +1 -0
- package/dist/delegation/cascading-revocation.d.ts +45 -0
- package/dist/delegation/cascading-revocation.d.ts.map +1 -0
- package/dist/delegation/cascading-revocation.js +150 -0
- package/dist/delegation/cascading-revocation.js.map +1 -0
- package/dist/delegation/delegation-graph.d.ts +49 -0
- package/dist/delegation/delegation-graph.d.ts.map +1 -0
- package/dist/delegation/delegation-graph.js +99 -0
- package/dist/delegation/delegation-graph.js.map +1 -0
- package/dist/delegation/did-key-resolver.d.ts +64 -0
- package/dist/delegation/did-key-resolver.d.ts.map +1 -0
- package/dist/delegation/did-key-resolver.js +157 -0
- package/dist/delegation/did-key-resolver.js.map +1 -0
- package/dist/delegation/did-web-resolver.d.ts +83 -0
- package/dist/delegation/did-web-resolver.d.ts.map +1 -0
- package/dist/delegation/did-web-resolver.js +218 -0
- package/dist/delegation/did-web-resolver.js.map +1 -0
- package/dist/delegation/index.d.ts +21 -0
- package/dist/delegation/index.d.ts.map +1 -0
- package/dist/delegation/index.js +21 -0
- package/dist/delegation/index.js.map +1 -0
- package/dist/delegation/outbound-headers.d.ts +79 -0
- package/dist/delegation/outbound-headers.d.ts.map +1 -0
- package/dist/delegation/outbound-headers.js +138 -0
- package/dist/delegation/outbound-headers.js.map +1 -0
- package/dist/delegation/outbound-proof.d.ts +43 -0
- package/dist/delegation/outbound-proof.d.ts.map +1 -0
- package/dist/delegation/outbound-proof.js +52 -0
- package/dist/delegation/outbound-proof.js.map +1 -0
- package/dist/delegation/statuslist-manager.d.ts +47 -0
- package/dist/delegation/statuslist-manager.d.ts.map +1 -0
- package/dist/delegation/statuslist-manager.js +139 -0
- package/dist/delegation/statuslist-manager.js.map +1 -0
- package/dist/delegation/storage/memory-graph-storage.d.ts +70 -0
- package/dist/delegation/storage/memory-graph-storage.d.ts.map +1 -0
- package/dist/delegation/storage/memory-graph-storage.js +145 -0
- package/dist/delegation/storage/memory-graph-storage.js.map +1 -0
- package/dist/delegation/storage/memory-statuslist-storage.d.ts +19 -0
- package/dist/delegation/storage/memory-statuslist-storage.d.ts.map +1 -0
- package/dist/delegation/storage/memory-statuslist-storage.js +33 -0
- package/dist/delegation/storage/memory-statuslist-storage.js.map +1 -0
- package/dist/delegation/utils.d.ts +49 -0
- package/dist/delegation/utils.d.ts.map +1 -0
- package/dist/delegation/utils.js +131 -0
- package/dist/delegation/utils.js.map +1 -0
- package/dist/delegation/vc-issuer.d.ts +56 -0
- package/dist/delegation/vc-issuer.d.ts.map +1 -0
- package/dist/delegation/vc-issuer.js +80 -0
- package/dist/delegation/vc-issuer.js.map +1 -0
- package/dist/delegation/vc-verifier.d.ts +112 -0
- package/dist/delegation/vc-verifier.d.ts.map +1 -0
- package/dist/delegation/vc-verifier.js +280 -0
- package/dist/delegation/vc-verifier.js.map +1 -0
- package/dist/errors.d.ts +42 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +45 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/logging/index.d.ts +2 -0
- package/dist/logging/index.d.ts.map +1 -0
- package/dist/logging/index.js +2 -0
- package/dist/logging/index.js.map +1 -0
- package/dist/logging/logger.d.ts +23 -0
- package/dist/logging/logger.d.ts.map +1 -0
- package/dist/logging/logger.js +82 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/middleware/index.d.ts +12 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +12 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/mcpi-transport.d.ts +39 -0
- package/dist/middleware/mcpi-transport.d.ts.map +1 -0
- package/dist/middleware/mcpi-transport.js +121 -0
- package/dist/middleware/mcpi-transport.js.map +1 -0
- package/dist/middleware/with-mcpi-server.d.ts +78 -0
- package/dist/middleware/with-mcpi-server.d.ts.map +1 -0
- package/dist/middleware/with-mcpi-server.js +109 -0
- package/dist/middleware/with-mcpi-server.js.map +1 -0
- package/dist/middleware/with-mcpi.d.ts +202 -0
- package/dist/middleware/with-mcpi.d.ts.map +1 -0
- package/dist/middleware/with-mcpi.js +625 -0
- package/dist/middleware/with-mcpi.js.map +1 -0
- package/dist/proof/errors.d.ts +49 -0
- package/dist/proof/errors.d.ts.map +1 -0
- package/dist/proof/errors.js +61 -0
- package/dist/proof/errors.js.map +1 -0
- package/dist/proof/generator.d.ts +65 -0
- package/dist/proof/generator.d.ts.map +1 -0
- package/dist/proof/generator.js +163 -0
- package/dist/proof/generator.js.map +1 -0
- package/dist/proof/index.d.ts +4 -0
- package/dist/proof/index.d.ts.map +1 -0
- package/dist/proof/index.js +4 -0
- package/dist/proof/index.js.map +1 -0
- package/dist/proof/verifier.d.ts +108 -0
- package/dist/proof/verifier.d.ts.map +1 -0
- package/dist/proof/verifier.js +299 -0
- package/dist/proof/verifier.js.map +1 -0
- package/dist/providers/base.d.ts +64 -0
- package/dist/providers/base.d.ts.map +1 -0
- package/dist/providers/base.js +19 -0
- package/dist/providers/base.js.map +1 -0
- package/dist/providers/index.d.ts +4 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +4 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/memory.d.ts +33 -0
- package/dist/providers/memory.d.ts.map +1 -0
- package/dist/providers/memory.js +102 -0
- package/dist/providers/memory.js.map +1 -0
- package/dist/providers/node-crypto.d.ts +26 -0
- package/dist/providers/node-crypto.d.ts.map +1 -0
- package/dist/providers/node-crypto.js +69 -0
- package/dist/providers/node-crypto.js.map +1 -0
- package/dist/session/index.d.ts +2 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +2 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/manager.d.ts +83 -0
- package/dist/session/manager.d.ts.map +1 -0
- package/dist/session/manager.js +267 -0
- package/dist/session/manager.js.map +1 -0
- package/dist/types/protocol.d.ts +320 -0
- package/dist/types/protocol.d.ts.map +1 -0
- package/dist/types/protocol.js +229 -0
- package/dist/types/protocol.js.map +1 -0
- package/dist/utils/base58.d.ts +31 -0
- package/dist/utils/base58.d.ts.map +1 -0
- package/dist/utils/base58.js +104 -0
- package/dist/utils/base58.js.map +1 -0
- package/dist/utils/base64.d.ts +13 -0
- package/dist/utils/base64.d.ts.map +1 -0
- package/dist/utils/base64.js +99 -0
- package/dist/utils/base64.js.map +1 -0
- package/dist/utils/crypto-service.d.ts +37 -0
- package/dist/utils/crypto-service.d.ts.map +1 -0
- package/dist/utils/crypto-service.js +154 -0
- package/dist/utils/crypto-service.js.map +1 -0
- package/dist/utils/did-helpers.d.ts +168 -0
- package/dist/utils/did-helpers.d.ts.map +1 -0
- package/dist/utils/did-helpers.js +211 -0
- package/dist/utils/did-helpers.js.map +1 -0
- package/dist/utils/ed25519-constants.d.ts +18 -0
- package/dist/utils/ed25519-constants.d.ts.map +1 -0
- package/dist/utils/ed25519-constants.js +21 -0
- package/dist/utils/ed25519-constants.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +115 -0
- package/schemas/README.md +117 -0
- package/schemas/delegation-credential.json +312 -0
- package/schemas/detached-proof.json +97 -0
- package/schemas/handshake-request.json +84 -0
- package/schemas/handshake-response.json +67 -0
- package/schemas/well-known-mcpi.json +176 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base58 Utilities (Bitcoin alphabet)
|
|
3
|
+
*
|
|
4
|
+
* Encoding and decoding utilities for Base58 (Bitcoin alphabet).
|
|
5
|
+
* Used for did:key multibase encoding (with 'z' prefix for base58btc).
|
|
6
|
+
*
|
|
7
|
+
* The Bitcoin alphabet excludes ambiguous characters (0, O, I, l).
|
|
8
|
+
*/
|
|
9
|
+
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
10
|
+
const ALPHABET_MAP = new Map();
|
|
11
|
+
// Build reverse lookup map
|
|
12
|
+
for (let i = 0; i < ALPHABET.length; i++) {
|
|
13
|
+
const char = ALPHABET[i];
|
|
14
|
+
if (char !== undefined) {
|
|
15
|
+
ALPHABET_MAP.set(char, i);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Encode bytes to Base58 (Bitcoin alphabet)
|
|
20
|
+
*
|
|
21
|
+
* @param bytes - Bytes to encode
|
|
22
|
+
* @returns Base58-encoded string
|
|
23
|
+
*/
|
|
24
|
+
export function base58Encode(bytes) {
|
|
25
|
+
if (bytes.length === 0)
|
|
26
|
+
return '';
|
|
27
|
+
// Convert bytes to big integer
|
|
28
|
+
let num = BigInt(0);
|
|
29
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
30
|
+
const byte = bytes[i];
|
|
31
|
+
if (byte !== undefined) {
|
|
32
|
+
num = num * BigInt(256) + BigInt(byte);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Convert to base58
|
|
36
|
+
let result = '';
|
|
37
|
+
while (num > 0) {
|
|
38
|
+
result = ALPHABET[Number(num % BigInt(58))] + result;
|
|
39
|
+
num = num / BigInt(58);
|
|
40
|
+
}
|
|
41
|
+
// Add leading zeros (encoded as '1' in base58)
|
|
42
|
+
for (let i = 0; i < bytes.length && bytes[i] === 0; i++) {
|
|
43
|
+
result = '1' + result;
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Decode Base58 (Bitcoin alphabet) to bytes
|
|
49
|
+
*
|
|
50
|
+
* @param encoded - Base58-encoded string
|
|
51
|
+
* @returns Decoded bytes
|
|
52
|
+
* @throws Error if input contains invalid characters
|
|
53
|
+
*/
|
|
54
|
+
export function base58Decode(encoded) {
|
|
55
|
+
if (encoded.length === 0)
|
|
56
|
+
return new Uint8Array(0);
|
|
57
|
+
// Convert base58 to big integer
|
|
58
|
+
let num = BigInt(0);
|
|
59
|
+
for (const char of encoded) {
|
|
60
|
+
const value = ALPHABET_MAP.get(char);
|
|
61
|
+
if (value === undefined) {
|
|
62
|
+
throw new Error(`Invalid base58 character: ${char}`);
|
|
63
|
+
}
|
|
64
|
+
num = num * BigInt(58) + BigInt(value);
|
|
65
|
+
}
|
|
66
|
+
// Convert big integer to bytes
|
|
67
|
+
const bytes = [];
|
|
68
|
+
while (num > 0) {
|
|
69
|
+
bytes.unshift(Number(num % BigInt(256)));
|
|
70
|
+
num = num / BigInt(256);
|
|
71
|
+
}
|
|
72
|
+
// Count leading zeros in input (encoded as '1')
|
|
73
|
+
let leadingZeros = 0;
|
|
74
|
+
for (const char of encoded) {
|
|
75
|
+
if (char === '1') {
|
|
76
|
+
leadingZeros++;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Prepend leading zero bytes
|
|
83
|
+
const result = new Uint8Array(leadingZeros + bytes.length);
|
|
84
|
+
// Leading zeros are already 0 in Uint8Array
|
|
85
|
+
result.set(bytes, leadingZeros);
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Validate a Base58 string
|
|
90
|
+
*
|
|
91
|
+
* @param encoded - String to validate
|
|
92
|
+
* @returns true if valid Base58, false otherwise
|
|
93
|
+
*/
|
|
94
|
+
export function isValidBase58(encoded) {
|
|
95
|
+
if (encoded.length === 0)
|
|
96
|
+
return true;
|
|
97
|
+
for (const char of encoded) {
|
|
98
|
+
if (!ALPHABET_MAP.has(char)) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=base58.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base58.js","sourceRoot":"","sources":["../../src/utils/base58.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,QAAQ,GAAG,4DAA4D,CAAC;AAC9E,MAAM,YAAY,GAAG,IAAI,GAAG,EAAkB,CAAC;AAE/C,2BAA2B;AAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;IACzC,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IACzB,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC5B,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,KAAiB;IAC5C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAElC,+BAA+B;IAC/B,IAAI,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACpB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
|
|
3
|
+
*
|
|
4
|
+
* Environment-aware base64url helpers that work in both Node.js and Cloudflare Workers.
|
|
5
|
+
* Uses Buffer in Node.js, TextEncoder/Decoder fallback for Workers.
|
|
6
|
+
*/
|
|
7
|
+
export declare function base64urlDecodeToString(input: string): string;
|
|
8
|
+
export declare function base64urlDecodeToBytes(input: string): Uint8Array;
|
|
9
|
+
export declare function base64urlEncodeFromString(input: string): string;
|
|
10
|
+
export declare function base64urlEncodeFromBytes(bytes: Uint8Array): string;
|
|
11
|
+
export declare function bytesToBase64(bytes: Uint8Array): string;
|
|
12
|
+
export declare function base64ToBytes(base64: string): Uint8Array;
|
|
13
|
+
//# sourceMappingURL=base64.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../src/utils/base64.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAyB7D;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAchE;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAgB/D;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAWlE;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CASvD;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAexD"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base64URL Encoding/Decoding Utilities
|
|
3
|
+
*
|
|
4
|
+
* Environment-aware base64url helpers that work in both Node.js and Cloudflare Workers.
|
|
5
|
+
* Uses Buffer in Node.js, TextEncoder/Decoder fallback for Workers.
|
|
6
|
+
*/
|
|
7
|
+
export function base64urlDecodeToString(input) {
|
|
8
|
+
const padded = addPadding(input);
|
|
9
|
+
const base64 = padded.replace(/-/g, '+').replace(/_/g, '/');
|
|
10
|
+
if (typeof Buffer !== 'undefined') {
|
|
11
|
+
const base64Regex = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
12
|
+
if (!base64Regex.test(base64)) {
|
|
13
|
+
throw new Error('Invalid base64url string: contains invalid characters');
|
|
14
|
+
}
|
|
15
|
+
return Buffer.from(base64, 'base64').toString('utf-8');
|
|
16
|
+
}
|
|
17
|
+
if (typeof atob !== 'undefined') {
|
|
18
|
+
const binaryString = atob(base64);
|
|
19
|
+
if (typeof TextDecoder !== 'undefined') {
|
|
20
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
21
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
22
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
23
|
+
}
|
|
24
|
+
return new TextDecoder().decode(bytes);
|
|
25
|
+
}
|
|
26
|
+
return binaryString;
|
|
27
|
+
}
|
|
28
|
+
throw new Error('Neither Buffer nor atob is available');
|
|
29
|
+
}
|
|
30
|
+
export function base64urlDecodeToBytes(input) {
|
|
31
|
+
const padded = addPadding(input);
|
|
32
|
+
const base64 = padded.replace(/-/g, '+').replace(/_/g, '/');
|
|
33
|
+
if (typeof atob !== 'undefined') {
|
|
34
|
+
const binaryString = atob(base64);
|
|
35
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
36
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
37
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
38
|
+
}
|
|
39
|
+
return bytes;
|
|
40
|
+
}
|
|
41
|
+
return new Uint8Array(Buffer.from(base64, 'base64'));
|
|
42
|
+
}
|
|
43
|
+
export function base64urlEncodeFromString(input) {
|
|
44
|
+
if (typeof Buffer !== 'undefined') {
|
|
45
|
+
const base64 = Buffer.from(input, 'utf-8').toString('base64');
|
|
46
|
+
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
47
|
+
}
|
|
48
|
+
if (typeof btoa !== 'undefined') {
|
|
49
|
+
const utf8Bytes = new TextEncoder().encode(input);
|
|
50
|
+
const binaryString = Array.from(utf8Bytes)
|
|
51
|
+
.map((byte) => String.fromCharCode(byte))
|
|
52
|
+
.join('');
|
|
53
|
+
const base64 = btoa(binaryString);
|
|
54
|
+
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
55
|
+
}
|
|
56
|
+
throw new Error('Neither Buffer nor btoa is available');
|
|
57
|
+
}
|
|
58
|
+
export function base64urlEncodeFromBytes(bytes) {
|
|
59
|
+
if (typeof btoa !== 'undefined') {
|
|
60
|
+
const binaryString = Array.from(bytes)
|
|
61
|
+
.map((byte) => String.fromCharCode(byte))
|
|
62
|
+
.join('');
|
|
63
|
+
const base64 = btoa(binaryString);
|
|
64
|
+
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
65
|
+
}
|
|
66
|
+
const base64 = Buffer.from(bytes).toString('base64');
|
|
67
|
+
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
68
|
+
}
|
|
69
|
+
export function bytesToBase64(bytes) {
|
|
70
|
+
if (typeof btoa !== 'undefined') {
|
|
71
|
+
const binaryString = Array.from(bytes)
|
|
72
|
+
.map((byte) => String.fromCharCode(byte))
|
|
73
|
+
.join('');
|
|
74
|
+
return btoa(binaryString);
|
|
75
|
+
}
|
|
76
|
+
return Buffer.from(bytes).toString('base64');
|
|
77
|
+
}
|
|
78
|
+
export function base64ToBytes(base64) {
|
|
79
|
+
let standardBase64 = base64.replace(/-/g, '+').replace(/_/g, '/');
|
|
80
|
+
const paddingNeeded = (4 - (standardBase64.length % 4)) % 4;
|
|
81
|
+
standardBase64 += '='.repeat(paddingNeeded);
|
|
82
|
+
if (typeof atob !== 'undefined') {
|
|
83
|
+
const binaryString = atob(standardBase64);
|
|
84
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
85
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
86
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
87
|
+
}
|
|
88
|
+
return bytes;
|
|
89
|
+
}
|
|
90
|
+
return new Uint8Array(Buffer.from(standardBase64, 'base64'));
|
|
91
|
+
}
|
|
92
|
+
function addPadding(input) {
|
|
93
|
+
const remainder = input.length % 4;
|
|
94
|
+
if (remainder === 0) {
|
|
95
|
+
return input;
|
|
96
|
+
}
|
|
97
|
+
return input + '='.repeat((4 - remainder) % 4);
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=base64.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.js","sourceRoot":"","sources":["../../src/utils/base64.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,UAAU,uBAAuB,CAAC,KAAa;IACnD,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAE5D,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,MAAM,WAAW,GAAG,wBAAwB,CAAC;QAC7C,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;QAC3E,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzD,CAAC;IAED,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE,CAAC;QAChC,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;QAClC,IAAI,OAAO,WAAW,KAAK,WAAW,EAAE,CAAC;YACvC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;YAClD,KAAK,IAAI,CAAC,GAAG,CA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AK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7C,KAAK,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACxC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IACnC,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;QACpB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CryptoService
|
|
3
|
+
*
|
|
4
|
+
* Centralized cryptographic operations service providing consistent
|
|
5
|
+
* signature verification across all platforms (Cloudflare, Node.js, etc.).
|
|
6
|
+
*/
|
|
7
|
+
import { CryptoProvider } from '../providers/base.js';
|
|
8
|
+
/**
|
|
9
|
+
* Minimal Ed25519 JWK interface
|
|
10
|
+
*/
|
|
11
|
+
export interface Ed25519JWK {
|
|
12
|
+
kty: 'OKP';
|
|
13
|
+
crv: 'Ed25519';
|
|
14
|
+
x: string;
|
|
15
|
+
kid?: string;
|
|
16
|
+
use?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ParsedJWS {
|
|
19
|
+
header: Record<string, unknown>;
|
|
20
|
+
payload?: Record<string, unknown>;
|
|
21
|
+
signatureBytes: Uint8Array;
|
|
22
|
+
signingInput: string;
|
|
23
|
+
}
|
|
24
|
+
export declare class CryptoService {
|
|
25
|
+
private cryptoProvider;
|
|
26
|
+
constructor(cryptoProvider: CryptoProvider);
|
|
27
|
+
verifyEd25519(data: Uint8Array, signature: Uint8Array, publicKey: string): Promise<boolean>;
|
|
28
|
+
parseJWS(jws: string): ParsedJWS;
|
|
29
|
+
verifyJWS(jws: string, publicKeyJwk: Ed25519JWK, options?: {
|
|
30
|
+
detachedPayload?: Uint8Array | string;
|
|
31
|
+
expectedKid?: string;
|
|
32
|
+
alg?: 'EdDSA';
|
|
33
|
+
}): Promise<boolean>;
|
|
34
|
+
private isValidEd25519JWK;
|
|
35
|
+
private jwkToBase64PublicKey;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=crypto-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto-service.d.ts","sourceRoot":"","sources":["../../src/utils/crypto-service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAStD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,KAAK,CAAC;IACX,GAAG,EAAE,SAAS,CAAC;IACf,CAAC,EAAE,MAAM,CAAC;IACV,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,cAAc,EAAE,UAAU,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,aAAa;IACZ,OAAO,CAAC,cAAc;gBAAd,cAAc,EAAE,cAAc;IAE5C,aAAa,CACjB,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,UAAU,EACrB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC;IAUnB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS;IA0C1B,SAAS,CACb,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,UAAU,EACxB,OAAO,CAAC,EAAE;QACR,eAAe,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;QACtC,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,GAAG,CAAC,EAAE,OAAO,CAAC;KACf,GACA,OAAO,CAAC,OAAO,CAAC;IAuFnB,OAAO,CAAC,iBAAiB;IAczB,OAAO,CAAC,oBAAoB;CAO7B"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CryptoService
|
|
3
|
+
*
|
|
4
|
+
* Centralized cryptographic operations service providing consistent
|
|
5
|
+
* signature verification across all platforms (Cloudflare, Node.js, etc.).
|
|
6
|
+
*/
|
|
7
|
+
import { logger } from '../logging/index.js';
|
|
8
|
+
import { base64urlDecodeToString, base64urlDecodeToBytes, base64urlEncodeFromBytes, bytesToBase64, } from './base64.js';
|
|
9
|
+
export class CryptoService {
|
|
10
|
+
cryptoProvider;
|
|
11
|
+
constructor(cryptoProvider) {
|
|
12
|
+
this.cryptoProvider = cryptoProvider;
|
|
13
|
+
}
|
|
14
|
+
async verifyEd25519(data, signature, publicKey) {
|
|
15
|
+
try {
|
|
16
|
+
const result = await this.cryptoProvider.verify(data, signature, publicKey);
|
|
17
|
+
return result === true;
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
logger.error('[CryptoService] Ed25519 verification error:', error);
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
parseJWS(jws) {
|
|
25
|
+
const parts = jws.split('.');
|
|
26
|
+
if (parts.length !== 3) {
|
|
27
|
+
throw new Error('Invalid JWS format: expected header.payload.signature');
|
|
28
|
+
}
|
|
29
|
+
const [headerB64, payloadB64, signatureB64] = parts;
|
|
30
|
+
let header;
|
|
31
|
+
try {
|
|
32
|
+
header = JSON.parse(base64urlDecodeToString(headerB64));
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
throw new Error(`Invalid header base64: ${error instanceof Error ? error.message : String(error)}`);
|
|
36
|
+
}
|
|
37
|
+
let payload;
|
|
38
|
+
if (payloadB64) {
|
|
39
|
+
try {
|
|
40
|
+
payload = JSON.parse(base64urlDecodeToString(payloadB64));
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
throw new Error(`Invalid payload base64: ${error instanceof Error ? error.message : String(error)}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
let signatureBytes;
|
|
47
|
+
try {
|
|
48
|
+
signatureBytes = base64urlDecodeToBytes(signatureB64);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
throw new Error(`Invalid signature base64: ${error instanceof Error ? error.message : String(error)}`);
|
|
52
|
+
}
|
|
53
|
+
const signingInput = `${headerB64}.${payloadB64}`;
|
|
54
|
+
return { header, payload, signatureBytes, signingInput };
|
|
55
|
+
}
|
|
56
|
+
async verifyJWS(jws, publicKeyJwk, options) {
|
|
57
|
+
try {
|
|
58
|
+
if (!this.isValidEd25519JWK(publicKeyJwk)) {
|
|
59
|
+
logger.error('[CryptoService] Invalid Ed25519 JWK format');
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (options?.expectedKid && publicKeyJwk.kid !== options.expectedKid) {
|
|
63
|
+
logger.error('[CryptoService] Key ID mismatch');
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
let parsed;
|
|
67
|
+
try {
|
|
68
|
+
parsed = this.parseJWS(jws);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if (options?.detachedPayload !== undefined) {
|
|
72
|
+
const parts = jws.split('.');
|
|
73
|
+
if (parts.length === 3 && parts[1] === '') {
|
|
74
|
+
try {
|
|
75
|
+
const headerB64 = parts[0];
|
|
76
|
+
const signatureB64 = parts[2];
|
|
77
|
+
const header = JSON.parse(base64urlDecodeToString(headerB64));
|
|
78
|
+
const signatureBytes = base64urlDecodeToBytes(signatureB64);
|
|
79
|
+
parsed = { header, payload: undefined, signatureBytes, signingInput: '' };
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
logger.error('[CryptoService] Invalid detached JWS format');
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
logger.error('[CryptoService] Invalid JWS format:', error);
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
logger.error('[CryptoService] Invalid JWS format:', error);
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const expectedAlg = options?.alg || 'EdDSA';
|
|
97
|
+
if (parsed.header['alg'] !== expectedAlg) {
|
|
98
|
+
logger.error(`[CryptoService] Unsupported algorithm: ${parsed.header['alg']}, expected ${expectedAlg}`);
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
let signingInputBytes;
|
|
102
|
+
if (options?.detachedPayload !== undefined) {
|
|
103
|
+
const headerB64 = jws.split('.')[0];
|
|
104
|
+
let payloadB64;
|
|
105
|
+
if (options.detachedPayload instanceof Uint8Array) {
|
|
106
|
+
payloadB64 = base64urlEncodeFromBytes(options.detachedPayload);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
payloadB64 = base64urlEncodeFromBytes(new TextEncoder().encode(options.detachedPayload));
|
|
110
|
+
}
|
|
111
|
+
signingInputBytes = new TextEncoder().encode(`${headerB64}.${payloadB64}`);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
if (!parsed.signingInput) {
|
|
115
|
+
logger.error('[CryptoService] Missing signing input for compact JWS');
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
signingInputBytes = new TextEncoder().encode(parsed.signingInput);
|
|
119
|
+
}
|
|
120
|
+
let publicKeyBase64;
|
|
121
|
+
try {
|
|
122
|
+
publicKeyBase64 = this.jwkToBase64PublicKey(publicKeyJwk);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
logger.error('[CryptoService] Failed to extract public key:', error);
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
return await this.verifyEd25519(signingInputBytes, parsed.signatureBytes, publicKeyBase64);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
logger.error('[CryptoService] JWS verification error:', error);
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
isValidEd25519JWK(jwk) {
|
|
136
|
+
return (typeof jwk === 'object' &&
|
|
137
|
+
jwk !== null &&
|
|
138
|
+
'kty' in jwk &&
|
|
139
|
+
jwk['kty'] === 'OKP' &&
|
|
140
|
+
'crv' in jwk &&
|
|
141
|
+
jwk['crv'] === 'Ed25519' &&
|
|
142
|
+
'x' in jwk &&
|
|
143
|
+
typeof jwk['x'] === 'string' &&
|
|
144
|
+
jwk['x'].length > 0);
|
|
145
|
+
}
|
|
146
|
+
jwkToBase64PublicKey(jwk) {
|
|
147
|
+
const publicKeyBytes = base64urlDecodeToBytes(jwk.x);
|
|
148
|
+
if (publicKeyBytes.length !== 32) {
|
|
149
|
+
throw new Error(`Invalid Ed25519 public key length: ${publicKeyBytes.length}`);
|
|
150
|
+
}
|
|
151
|
+
return bytesToBase64(publicKeyBytes);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=crypto-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto-service.js","sourceRoot":"","sources":["../../src/utils/crypto-service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,wBAAwB,EACxB,aAAa,GACd,MAAM,aAAa,CAAC;AAoBrB,MAAM,OAAO,aAAa;IACJ;IAApB,YAAoB,cAA8B;QAA9B,mBAAc,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O,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAEO,iBAAiB,CAAC,GAAY;QACpC,OAAO,CACL,OAAO,GAAG,KAAK,QAAQ;YACvB,GAAG,KAAK,IAAI;YACZ,KAAK,IAAI,GAAG;YACX,GAA+B,CAAC,KAAK,CAAC,KAAK,KAAK;YACjD,KAAK,IAAI,GAAG;YACX,GAA+B,CAAC,KAAK,CAAC,KAAK,SAAS;YACrD,GAAG,IAAI,GAAG;YACV,OAAQ,GAA+B,CAAC,GAAG,CAAC,KAAK,QAAQ;YACvD,GAA+B,CAAC,GAAG,CAAY,CAAC,MAAM,GAAG,CAAC,CAC7D,CAAC;IACJ,CAAC;IAEO,oBAAoB,CAAC,GAAe;QAC1C,MAAM,cAAc,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACrD,IAAI,cAAc,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,sCAAsC,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC;QACjF,CAAC;QACD,OAAO,aAAa,CAAC,cAAc,CAAC,CAAC;IACvC,CAAC;CACF"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DID Validation and Helper Utilities
|
|
3
|
+
*
|
|
4
|
+
* Centralized utilities for DID validation, normalization, and handling.
|
|
5
|
+
* Promotes DRY principle and consistency across the codebase.
|
|
6
|
+
*
|
|
7
|
+
* @package @kya-os/mcp/utils
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Check if a string is a valid DID format
|
|
11
|
+
*
|
|
12
|
+
* @param did - String to validate
|
|
13
|
+
* @returns true if string starts with "did:"
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* isValidDid("did:key:z6Mk...") // true
|
|
18
|
+
* isValidDid("not-a-did") // false
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function isValidDid(did: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Get the DID method from a DID string
|
|
24
|
+
*
|
|
25
|
+
* @param did - DID string
|
|
26
|
+
* @returns DID method (e.g., "key", "web") or null if invalid
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* getDidMethod("did:key:z6Mk...") // "key"
|
|
31
|
+
* getDidMethod("did:web:example.com") // "web"
|
|
32
|
+
* getDidMethod("invalid") // null
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function getDidMethod(did: string): string | null;
|
|
36
|
+
/**
|
|
37
|
+
* Normalize a DID string (trim whitespace)
|
|
38
|
+
*
|
|
39
|
+
* @param did - DID string to normalize
|
|
40
|
+
* @returns Normalized DID string
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* normalizeDid(" did:key:z6Mk... ") // "did:key:z6Mk..."
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function normalizeDid(did: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Compare two DIDs for equality (case-sensitive)
|
|
50
|
+
*
|
|
51
|
+
* @param did1 - First DID
|
|
52
|
+
* @param did2 - Second DID
|
|
53
|
+
* @returns true if DIDs are equal (after normalization)
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* compareDids("did:key:z6Mk...", "did:key:z6Mk...") // true
|
|
58
|
+
* compareDids("did:key:z6Mk...", "did:web:example.com") // false
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function compareDids(did1: string, did2: string): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Extract server DID from config (supports both old and new field names)
|
|
64
|
+
*
|
|
65
|
+
* Supports backward compatibility by reading both `serverDid` and deprecated `agentDid`.
|
|
66
|
+
* Prefers `serverDid` if both are present.
|
|
67
|
+
*
|
|
68
|
+
* @param config - Config object with identity field
|
|
69
|
+
* @returns Server DID string
|
|
70
|
+
* @throws Error if neither serverDid nor agentDid is configured
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* // New config
|
|
75
|
+
* getServerDid({ identity: { serverDid: "did:web:example.com" } }) // "did:web:example.com"
|
|
76
|
+
*
|
|
77
|
+
* // Old config (backward compatibility)
|
|
78
|
+
* getServerDid({ identity: { agentDid: "did:web:example.com" } }) // "did:web:example.com"
|
|
79
|
+
*
|
|
80
|
+
* // Prefers serverDid over agentDid
|
|
81
|
+
* getServerDid({ identity: { serverDid: "new", agentDid: "old" } }) // "new"
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare function getServerDid(config: {
|
|
85
|
+
identity: {
|
|
86
|
+
serverDid?: string;
|
|
87
|
+
agentDid?: string;
|
|
88
|
+
};
|
|
89
|
+
}): string;
|
|
90
|
+
/**
|
|
91
|
+
* Extract agent ID from DID
|
|
92
|
+
*
|
|
93
|
+
* The agent ID is the last component of the DID.
|
|
94
|
+
*
|
|
95
|
+
* @param did - DID string
|
|
96
|
+
* @returns Agent ID (last component of DID)
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* extractAgentId("did:web:example.com:agents:my-agent") // "my-agent"
|
|
101
|
+
* extractAgentId("did:web:localhost:3000:agents:12912feb") // "12912feb"
|
|
102
|
+
* extractAgentId("did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK") // "z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK"
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function extractAgentId(did: string): string;
|
|
106
|
+
/**
|
|
107
|
+
* Extract agent slug from DID
|
|
108
|
+
*
|
|
109
|
+
* Agent slug is the same as agent ID - the last component of the DID.
|
|
110
|
+
* For DID format: did:web:example.com:agents:my-agent
|
|
111
|
+
* Returns: my-agent
|
|
112
|
+
*
|
|
113
|
+
* @param did - DID string
|
|
114
|
+
* @returns Agent slug (last component of DID)
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* extractAgentSlug("did:web:example.com:agents:my-agent") // "my-agent"
|
|
119
|
+
* extractAgentSlug("did:web:localhost:3000:agents:12912feb") // "12912feb"
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare function extractAgentSlug(did: string): string;
|
|
123
|
+
/**
|
|
124
|
+
* Generate a did:key from Ed25519 public key bytes
|
|
125
|
+
*
|
|
126
|
+
* Following spec: https://w3c-ccg.github.io/did-method-key/
|
|
127
|
+
* Format: did:key:z<multibase-base58btc(<multicodec-ed25519-pub><publicKey>)>
|
|
128
|
+
*
|
|
129
|
+
* @param publicKeyBytes - Ed25519 public key as Uint8Array (32 bytes)
|
|
130
|
+
* @returns did:key string
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const publicKey = new Uint8Array(32); // 32-byte Ed25519 public key
|
|
135
|
+
* const did = generateDidKeyFromBytes(publicKey);
|
|
136
|
+
* // did = "did:key:z6Mk..."
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export declare function generateDidKeyFromBytes(publicKeyBytes: Uint8Array): string;
|
|
140
|
+
/**
|
|
141
|
+
* Generate a did:key from base64-encoded Ed25519 public key
|
|
142
|
+
*
|
|
143
|
+
* Convenience wrapper around generateDidKeyFromBytes for base64-encoded keys.
|
|
144
|
+
*
|
|
145
|
+
* @param publicKeyBase64 - Ed25519 public key as base64 string
|
|
146
|
+
* @returns did:key string
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* const publicKeyBase64 = "...base64 encoded key...";
|
|
151
|
+
* const did = generateDidKeyFromBase64(publicKeyBase64);
|
|
152
|
+
* // did = "did:key:z6Mk..."
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export declare function generateDidKeyFromBase64(publicKeyBase64: string): string;
|
|
156
|
+
/**
|
|
157
|
+
* Get the spec-compliant fragment identifier for a did:key DID.
|
|
158
|
+
*
|
|
159
|
+
* Per the did:key spec (W3C CCG), the fragment equals the multibase-encoded
|
|
160
|
+
* public key value (the DID-specific-id). For example:
|
|
161
|
+
* did:key:z6MkABC... → z6MkABC...
|
|
162
|
+
*
|
|
163
|
+
* @see https://w3c-ccg.github.io/did-key-spec/#document-creation-algorithm
|
|
164
|
+
* @param did - A did:key DID string
|
|
165
|
+
* @returns The fragment identifier (multibase value), or 'keys-1' as fallback for non-did:key
|
|
166
|
+
*/
|
|
167
|
+
export declare function didKeyFragment(did: string): string;
|
|
168
|
+
//# sourceMappingURL=did-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"did-helpers.d.ts","sourceRoot":"","sources":["../../src/utils/did-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMvD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAE/D;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE;IACnC,QAAQ,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACrD,GAAG,MAAM,CAMT;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIlD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD;AAQD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,uBAAuB,CAAC,cAAc,EAAE,UAAU,GAAG,MAAM,CAW1E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,wBAAwB,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAMxE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAMlD"}
|