@cloakedagent/sdk 0.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/README.md +90 -0
- package/dist/agent.d.ts +321 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +877 -0
- package/dist/agent.js.map +1 -0
- package/dist/config.d.ts +33 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +64 -0
- package/dist/config.js.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +9 -0
- package/dist/constants.js.map +1 -0
- package/dist/idl.json +1347 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/index.d.ts +7 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +374 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/tools.d.ts +26 -0
- package/dist/mcp/tools.d.ts.map +1 -0
- package/dist/mcp/tools.js +320 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/mcp/types.d.ts +61 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +4 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/relayer.d.ts +130 -0
- package/dist/relayer.d.ts.map +1 -0
- package/dist/relayer.js +225 -0
- package/dist/relayer.js.map +1 -0
- package/dist/signer.d.ts +18 -0
- package/dist/signer.d.ts.map +1 -0
- package/dist/signer.js +34 -0
- package/dist/signer.js.map +1 -0
- package/dist/token.d.ts +320 -0
- package/dist/token.d.ts.map +1 -0
- package/dist/token.js +896 -0
- package/dist/token.js.map +1 -0
- package/dist/types.d.ts +66 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/zk/browser-prover.d.ts +85 -0
- package/dist/zk/browser-prover.d.ts.map +1 -0
- package/dist/zk/browser-prover.js +260 -0
- package/dist/zk/browser-prover.js.map +1 -0
- package/dist/zk/discovery.d.ts +65 -0
- package/dist/zk/discovery.d.ts.map +1 -0
- package/dist/zk/discovery.js +143 -0
- package/dist/zk/discovery.js.map +1 -0
- package/dist/zk/index.d.ts +14 -0
- package/dist/zk/index.d.ts.map +1 -0
- package/dist/zk/index.js +47 -0
- package/dist/zk/index.js.map +1 -0
- package/dist/zk/ownership_proof.json +1 -0
- package/dist/zk/poseidon.d.ts +31 -0
- package/dist/zk/poseidon.d.ts.map +1 -0
- package/dist/zk/poseidon.js +103 -0
- package/dist/zk/poseidon.js.map +1 -0
- package/dist/zk/prover.d.ts +49 -0
- package/dist/zk/prover.d.ts.map +1 -0
- package/dist/zk/prover.js +120 -0
- package/dist/zk/prover.js.map +1 -0
- package/dist/zk/secrets.d.ts +62 -0
- package/dist/zk/secrets.d.ts.map +1 -0
- package/dist/zk/secrets.js +98 -0
- package/dist/zk/secrets.js.map +1 -0
- package/package.json +74 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ZK Proof generation for private agent ownership
|
|
4
|
+
*
|
|
5
|
+
* Client-side proving using bb.js WASM - secret never leaves the browser.
|
|
6
|
+
* Proof is sent to backend for attestation (Groth16 conversion for Solana).
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.setBackendUrl = void 0;
|
|
10
|
+
exports.initProver = initProver;
|
|
11
|
+
exports.isProverReady = isProverReady;
|
|
12
|
+
exports.generateOwnershipProof = generateOwnershipProof;
|
|
13
|
+
exports.proofToInstructionArgs = proofToInstructionArgs;
|
|
14
|
+
const config_1 = require("../config");
|
|
15
|
+
const browser_prover_1 = require("./browser-prover");
|
|
16
|
+
// Prover readiness state
|
|
17
|
+
let proverReady = false;
|
|
18
|
+
/**
|
|
19
|
+
* Initialize the prover (checks backend availability)
|
|
20
|
+
*
|
|
21
|
+
* Should be called once on app load. Verifies the backend
|
|
22
|
+
* attestation prover service is available and ready.
|
|
23
|
+
*/
|
|
24
|
+
async function initProver() {
|
|
25
|
+
try {
|
|
26
|
+
// Check backend is available
|
|
27
|
+
const response = await fetch(`${(0, config_1.getBackendUrl)()}/api/prover/status`);
|
|
28
|
+
if (!response.ok) {
|
|
29
|
+
throw new Error(`Backend returned ${response.status}`);
|
|
30
|
+
}
|
|
31
|
+
const status = (await response.json());
|
|
32
|
+
if (!status.ready) {
|
|
33
|
+
throw new Error(status.error || "Prover not ready");
|
|
34
|
+
}
|
|
35
|
+
// Verify Poseidon hash compatibility between SDK and Noir circuit
|
|
36
|
+
// This catches build/version mismatches early
|
|
37
|
+
if ((0, browser_prover_1.isBrowserProverAvailable)()) {
|
|
38
|
+
await (0, browser_prover_1.verifyPoseidonCompatibility)();
|
|
39
|
+
}
|
|
40
|
+
proverReady = true;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
throw new Error(`Failed to initialize prover: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Check if prover is initialized
|
|
48
|
+
*/
|
|
49
|
+
function isProverReady() {
|
|
50
|
+
return proverReady;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Convert browser UltraHonk proof to Solana-compatible Groth16 format
|
|
54
|
+
*
|
|
55
|
+
* Attestation flow:
|
|
56
|
+
* 1. Browser generates UltraHonk proof (secret stays local)
|
|
57
|
+
* 2. Send proof bytes + public inputs to backend (NO secret transmitted!)
|
|
58
|
+
* 3. Backend verifies UltraHonk proof using bb.js
|
|
59
|
+
* 4. If valid, backend generates Groth16 attestation proof
|
|
60
|
+
* 5. Returns Groth16 proof for Solana
|
|
61
|
+
*
|
|
62
|
+
* Privacy guarantee: The agent_secret NEVER leaves the browser.
|
|
63
|
+
*/
|
|
64
|
+
async function browserProofToOwnershipProof(browserProof) {
|
|
65
|
+
const response = await fetch(`${(0, config_1.getBackendUrl)()}/api/prove/attestation`, {
|
|
66
|
+
method: "POST",
|
|
67
|
+
headers: { "Content-Type": "application/json" },
|
|
68
|
+
body: JSON.stringify({
|
|
69
|
+
proofBytes: Array.from(browserProof.proof),
|
|
70
|
+
publicInputs: browserProof.publicInputs,
|
|
71
|
+
}),
|
|
72
|
+
});
|
|
73
|
+
if (!response.ok) {
|
|
74
|
+
const error = (await response.json().catch(() => ({ error: "Unknown error" })));
|
|
75
|
+
throw new Error(`Attestation proof failed: ${error.error || error.details || "Unknown error"}`);
|
|
76
|
+
}
|
|
77
|
+
const result = (await response.json());
|
|
78
|
+
return {
|
|
79
|
+
proofBytes: new Uint8Array(result.proofBytes),
|
|
80
|
+
witnessBytes: new Uint8Array(result.witnessBytes),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Generate ZK ownership proof
|
|
85
|
+
*
|
|
86
|
+
* Uses client-side bb.js to generate UltraHonk proof, then sends
|
|
87
|
+
* proof artifacts to backend for Groth16 attestation.
|
|
88
|
+
*
|
|
89
|
+
* Requires browser environment with SharedArrayBuffer support.
|
|
90
|
+
*
|
|
91
|
+
* @param agentSecret - The private agent secret
|
|
92
|
+
* @param commitment - The public commitment (must match on-chain)
|
|
93
|
+
* @returns Proof components for Solana program
|
|
94
|
+
*/
|
|
95
|
+
async function generateOwnershipProof(agentSecret, commitment) {
|
|
96
|
+
if (!(0, browser_prover_1.isBrowserProverAvailable)()) {
|
|
97
|
+
throw new Error("Client-side proving requires a browser with SharedArrayBuffer support. " +
|
|
98
|
+
"Ensure your site is served with proper COOP/COEP headers.");
|
|
99
|
+
}
|
|
100
|
+
// Generate UltraHonk proof in browser (secret stays local)
|
|
101
|
+
const browserProof = await (0, browser_prover_1.generateOwnershipProofBrowser)(agentSecret, commitment);
|
|
102
|
+
// Send proof to backend for attestation (secret NOT transmitted)
|
|
103
|
+
return browserProofToOwnershipProof(browserProof);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Convert proof to format expected by Solana program
|
|
107
|
+
*
|
|
108
|
+
* @param proof - Ownership proof
|
|
109
|
+
* @returns Arrays ready for program instruction
|
|
110
|
+
*/
|
|
111
|
+
function proofToInstructionArgs(proof) {
|
|
112
|
+
return {
|
|
113
|
+
proofBytes: Array.from(proof.proofBytes),
|
|
114
|
+
witnessBytes: Array.from(proof.witnessBytes),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
// Re-export setBackendUrl for backwards compatibility
|
|
118
|
+
var config_2 = require("../config");
|
|
119
|
+
Object.defineProperty(exports, "setBackendUrl", { enumerable: true, get: function () { return config_2.setBackendUrl; } });
|
|
120
|
+
//# sourceMappingURL=prover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prover.js","sourceRoot":"","sources":["../../src/zk/prover.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AA6CH,gCAwBC;AAKD,sCAEC;AAmDD,wDAgBC;AAQD,wDAQC;AA7JD,sCAA0C;AAC1C,qDAK0B;AA4B1B,yBAAyB;AACzB,IAAI,WAAW,GAAG,KAAK,CAAC;AAExB;;;;;GAKG;AACI,KAAK,UAAU,UAAU;IAC9B,IAAI,CAAC;QACH,6BAA6B;QAC7B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAA,sBAAa,GAAE,oBAAoB,CAAC,CAAC;QACrE,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,oBAAoB,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;QACzD,CAAC;QACD,MAAM,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAyB,CAAC;QAC/D,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,kBAAkB,CAAC,CAAC;QACtD,CAAC;QAED,kEAAkE;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E,IAAI,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC;QAC7C,YAAY,EAAE,IAAI,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC;KAClD,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACI,KAAK,UAAU,sBAAsB,CAC1C,WAAmB,EACnB,UAAkB;IAElB,IAAI,CAAC,IAAA,yCAAwB,GAAE,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CACb,yEAAyE;YACzE,2DAA2D,CAC5D,CAAC;IACJ,CAAC;IAED,2DAA2D;IAC3D,MAAM,YAAY,GAAG,MAAM,IAAA,8CAA6B,EAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IAElF,iEAAiE;IACjE,OAAO,4BAA4B,CAAC,YAAY,CAAC,CAAC;AACpD,CAAC;AAED;;;;;GAKG;AACH,SAAgB,sBAAsB,CAAC,KAAqB;IAI1D,OAAO;QACL,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;QACxC,YAAY,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC;KAC7C,CAAC;AACJ,CAAC;AAED,sDAAsD;AACtD,oCAA0C;AAAjC,uGAAA,aAAa,OAAA"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic secret derivation for private agents
|
|
3
|
+
*
|
|
4
|
+
* The secret derivation chain:
|
|
5
|
+
* 1. User signs "Cloak Private Agent" → signature
|
|
6
|
+
* 2. master_secret = sha256(signature)
|
|
7
|
+
* 3. agent_secret = poseidon(master_secret, nonce)
|
|
8
|
+
* 4. commitment = poseidon(agent_secret)
|
|
9
|
+
*
|
|
10
|
+
* Same wallet always produces same master_secret, enabling
|
|
11
|
+
* deterministic discovery of private agents across devices.
|
|
12
|
+
*/
|
|
13
|
+
/** Maximum agents to scan during discovery */
|
|
14
|
+
export declare const MAX_AGENTS = 100;
|
|
15
|
+
/** Secrets for a private agent */
|
|
16
|
+
export interface PrivateAgentSecrets {
|
|
17
|
+
masterSecret: bigint;
|
|
18
|
+
agentSecret: bigint;
|
|
19
|
+
commitment: bigint;
|
|
20
|
+
nonce: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Derive master secret from wallet signature
|
|
24
|
+
*
|
|
25
|
+
* Same wallet always produces same master secret, enabling
|
|
26
|
+
* deterministic discovery across devices.
|
|
27
|
+
*
|
|
28
|
+
* @param signMessage - Wallet's signMessage function
|
|
29
|
+
* @returns Master secret as bigint
|
|
30
|
+
*/
|
|
31
|
+
export declare function deriveMasterSecret(signMessage: (message: Uint8Array) => Promise<Uint8Array>): Promise<bigint>;
|
|
32
|
+
/**
|
|
33
|
+
* Derive agent secret and commitment for a specific nonce
|
|
34
|
+
*
|
|
35
|
+
* @param masterSecret - Master secret from wallet signature
|
|
36
|
+
* @param nonce - Agent index (0, 1, 2, ...)
|
|
37
|
+
* @returns Agent secret and commitment
|
|
38
|
+
*/
|
|
39
|
+
export declare function deriveAgentSecrets(masterSecret: bigint, nonce: number): Promise<{
|
|
40
|
+
agentSecret: bigint;
|
|
41
|
+
commitment: bigint;
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Convert commitment bigint to bytes for on-chain storage
|
|
45
|
+
*
|
|
46
|
+
* @param commitment - Commitment as bigint
|
|
47
|
+
* @returns 32-byte array
|
|
48
|
+
*/
|
|
49
|
+
export declare function commitmentToBytes(commitment: bigint): Uint8Array;
|
|
50
|
+
/**
|
|
51
|
+
* Convert bytes to commitment bigint
|
|
52
|
+
*
|
|
53
|
+
* @param bytes - 32-byte array
|
|
54
|
+
* @returns Commitment as bigint
|
|
55
|
+
*/
|
|
56
|
+
export declare function bytesToCommitment(bytes: Uint8Array): bigint;
|
|
57
|
+
/**
|
|
58
|
+
* Get the sign message used for master secret derivation
|
|
59
|
+
* (Useful for wallet UI to show what's being signed)
|
|
60
|
+
*/
|
|
61
|
+
export declare function getSignMessage(): string;
|
|
62
|
+
//# sourceMappingURL=secrets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../src/zk/secrets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAOH,8CAA8C;AAC9C,eAAO,MAAM,UAAU,MAAM,CAAC;AAE9B,kCAAkC;AAClC,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CACtC,WAAW,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,OAAO,CAAC,UAAU,CAAC,GACxD,OAAO,CAAC,MAAM,CAAC,CAgBjB;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CACtC,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CAQtD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,CAQhE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAM3D;AAED;;;GAGG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAEvC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Deterministic secret derivation for private agents
|
|
4
|
+
*
|
|
5
|
+
* The secret derivation chain:
|
|
6
|
+
* 1. User signs "Cloak Private Agent" → signature
|
|
7
|
+
* 2. master_secret = sha256(signature)
|
|
8
|
+
* 3. agent_secret = poseidon(master_secret, nonce)
|
|
9
|
+
* 4. commitment = poseidon(agent_secret)
|
|
10
|
+
*
|
|
11
|
+
* Same wallet always produces same master_secret, enabling
|
|
12
|
+
* deterministic discovery of private agents across devices.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.MAX_AGENTS = void 0;
|
|
16
|
+
exports.deriveMasterSecret = deriveMasterSecret;
|
|
17
|
+
exports.deriveAgentSecrets = deriveAgentSecrets;
|
|
18
|
+
exports.commitmentToBytes = commitmentToBytes;
|
|
19
|
+
exports.bytesToCommitment = bytesToCommitment;
|
|
20
|
+
exports.getSignMessage = getSignMessage;
|
|
21
|
+
const poseidon_1 = require("./poseidon");
|
|
22
|
+
/** Message signed to derive master secret */
|
|
23
|
+
const SIGN_MESSAGE = "Cloak Private Agent";
|
|
24
|
+
/** Maximum agents to scan during discovery */
|
|
25
|
+
exports.MAX_AGENTS = 100;
|
|
26
|
+
/**
|
|
27
|
+
* Derive master secret from wallet signature
|
|
28
|
+
*
|
|
29
|
+
* Same wallet always produces same master secret, enabling
|
|
30
|
+
* deterministic discovery across devices.
|
|
31
|
+
*
|
|
32
|
+
* @param signMessage - Wallet's signMessage function
|
|
33
|
+
* @returns Master secret as bigint
|
|
34
|
+
*/
|
|
35
|
+
async function deriveMasterSecret(signMessage) {
|
|
36
|
+
const message = new TextEncoder().encode(SIGN_MESSAGE);
|
|
37
|
+
const signature = await signMessage(message);
|
|
38
|
+
// Hash signature to get master secret using Web Crypto API
|
|
39
|
+
// Note: wrap in Uint8Array for compatibility with wallet adapters
|
|
40
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", new Uint8Array(signature));
|
|
41
|
+
const hashArray = new Uint8Array(hashBuffer);
|
|
42
|
+
// Convert to bigint (take first 31 bytes to fit in BN254 field)
|
|
43
|
+
let masterSecret = BigInt(0);
|
|
44
|
+
for (let i = 0; i < 31; i++) {
|
|
45
|
+
masterSecret = (masterSecret << BigInt(8)) | BigInt(hashArray[i]);
|
|
46
|
+
}
|
|
47
|
+
return masterSecret;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Derive agent secret and commitment for a specific nonce
|
|
51
|
+
*
|
|
52
|
+
* @param masterSecret - Master secret from wallet signature
|
|
53
|
+
* @param nonce - Agent index (0, 1, 2, ...)
|
|
54
|
+
* @returns Agent secret and commitment
|
|
55
|
+
*/
|
|
56
|
+
async function deriveAgentSecrets(masterSecret, nonce) {
|
|
57
|
+
// agent_secret = poseidon(master_secret, nonce)
|
|
58
|
+
const agentSecret = await (0, poseidon_1.poseidon)([masterSecret, BigInt(nonce)]);
|
|
59
|
+
// commitment = poseidon(agent_secret)
|
|
60
|
+
const commitment = await (0, poseidon_1.poseidon)([agentSecret]);
|
|
61
|
+
return { agentSecret, commitment };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Convert commitment bigint to bytes for on-chain storage
|
|
65
|
+
*
|
|
66
|
+
* @param commitment - Commitment as bigint
|
|
67
|
+
* @returns 32-byte array
|
|
68
|
+
*/
|
|
69
|
+
function commitmentToBytes(commitment) {
|
|
70
|
+
const bytes = new Uint8Array(32);
|
|
71
|
+
let value = commitment;
|
|
72
|
+
for (let i = 31; i >= 0; i--) {
|
|
73
|
+
bytes[i] = Number(value & BigInt(0xff));
|
|
74
|
+
value >>= BigInt(8);
|
|
75
|
+
}
|
|
76
|
+
return bytes;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Convert bytes to commitment bigint
|
|
80
|
+
*
|
|
81
|
+
* @param bytes - 32-byte array
|
|
82
|
+
* @returns Commitment as bigint
|
|
83
|
+
*/
|
|
84
|
+
function bytesToCommitment(bytes) {
|
|
85
|
+
let commitment = BigInt(0);
|
|
86
|
+
for (let i = 0; i < 32; i++) {
|
|
87
|
+
commitment = (commitment << BigInt(8)) | BigInt(bytes[i]);
|
|
88
|
+
}
|
|
89
|
+
return commitment;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get the sign message used for master secret derivation
|
|
93
|
+
* (Useful for wallet UI to show what's being signed)
|
|
94
|
+
*/
|
|
95
|
+
function getSignMessage() {
|
|
96
|
+
return SIGN_MESSAGE;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=secrets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../../src/zk/secrets.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AA2BH,gDAkBC;AASD,gDAWC;AAQD,8CAQC;AAQD,8CAMC;AAMD,wCAEC;AArGD,yCAAsC;AAEtC,6CAA6C;AAC7C,MAAM,YAAY,GAAG,qBAAqB,CAAC;AAE3C,8CAA8C;AACjC,QAAA,UAAU,GAAG,GAAG,CAAC;AAU9B;;;;;;;;GAQG;AACI,KAAK,UAAU,kBAAkB,CACtC,WAAyD;IAEzD,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IACvD,MAAM,SAAS,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,CAAC;IAE7C,2DAA2D;IAC3D,kEAAkE;IAClE,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;IACpF,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC;IAE7C,gEAAgE;IAChE,IAAI,YAAY,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,YAAY,GAAG,CAAC,YAAY,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IACpE,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,kBAAkB,CACtC,YAAoB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akedagent/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Trustless spending accounts for AI agents on Solana",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=20.0.0"
|
|
7
|
+
},
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./mcp": {
|
|
16
|
+
"types": "./dist/mcp/index.d.ts",
|
|
17
|
+
"default": "./dist/mcp/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md"
|
|
23
|
+
],
|
|
24
|
+
"homepage": "https://cloakedagent.com",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/CloakedAgent/cloaked"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"bin": {
|
|
33
|
+
"cloaked-mcp": "./dist/mcp/index.js"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc",
|
|
37
|
+
"build:mcp": "tsc && chmod +x dist/mcp/index.js",
|
|
38
|
+
"mcp": "ts-node src/mcp/index.ts",
|
|
39
|
+
"test": "mocha --require ts-node/register 'tests/**/*.ts'",
|
|
40
|
+
"test:watch": "mocha --require ts-node/register --watch 'tests/**/*.ts'"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"solana",
|
|
44
|
+
"ai-agents",
|
|
45
|
+
"mcp",
|
|
46
|
+
"claude",
|
|
47
|
+
"spending-limits",
|
|
48
|
+
"crypto-payments",
|
|
49
|
+
"x402",
|
|
50
|
+
"zk-proofs",
|
|
51
|
+
"model-context-protocol"
|
|
52
|
+
],
|
|
53
|
+
"author": "Cloaked Agent",
|
|
54
|
+
"license": "MIT",
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@aztec/bb.js": "3.0.3",
|
|
57
|
+
"@coral-xyz/anchor": "^0.32.1",
|
|
58
|
+
"@modelcontextprotocol/sdk": "^1.25.3",
|
|
59
|
+
"@noir-lang/noir_js": "^1.0.0-beta.18",
|
|
60
|
+
"@solana/web3.js": "^1.98.0",
|
|
61
|
+
"bs58": "^5.0.0",
|
|
62
|
+
"circomlibjs": "^0.1.7",
|
|
63
|
+
"tweetnacl": "^1.0.3"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@types/chai": "^4.3.20",
|
|
67
|
+
"@types/mocha": "^10.0.10",
|
|
68
|
+
"@types/node": "^22.0.0",
|
|
69
|
+
"chai": "^4.5.0",
|
|
70
|
+
"mocha": "^10.8.0",
|
|
71
|
+
"ts-node": "^10.9.2",
|
|
72
|
+
"typescript": "^5.7.0"
|
|
73
|
+
}
|
|
74
|
+
}
|