@kairoguard/sdk 0.0.1
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 +92 -0
- package/dist/auditBundle.d.ts +28 -0
- package/dist/auditBundle.js +20 -0
- package/dist/backend.d.ts +288 -0
- package/dist/backend.js +107 -0
- package/dist/bitcoinIntent.d.ts +104 -0
- package/dist/bitcoinIntent.js +126 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +237 -0
- package/dist/client.d.ts +186 -0
- package/dist/client.js +767 -0
- package/dist/evm.d.ts +19 -0
- package/dist/evm.js +53 -0
- package/dist/evmIntent.d.ts +11 -0
- package/dist/evmIntent.js +12 -0
- package/dist/ika-protocol.d.ts +85 -0
- package/dist/ika-protocol.js +156 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/keystore.d.ts +29 -0
- package/dist/keystore.js +53 -0
- package/dist/skill-templates.d.ts +9 -0
- package/dist/skill-templates.js +252 -0
- package/dist/solanaIntent.d.ts +128 -0
- package/dist/solanaIntent.js +214 -0
- package/dist/suiCustody.d.ts +14 -0
- package/dist/suiCustody.js +183 -0
- package/dist/suiReceipts.d.ts +27 -0
- package/dist/suiReceipts.js +203 -0
- package/dist/suiResult.d.ts +8 -0
- package/dist/suiResult.js +12 -0
- package/dist/suiTxBuilders.d.ts +15 -0
- package/dist/suiTxBuilders.js +38 -0
- package/dist/types.d.ts +38 -0
- package/dist/types.js +1 -0
- package/package.json +29 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bitcoin Intent Utilities
|
|
3
|
+
*
|
|
4
|
+
* Client-side helpers for Bitcoin transaction intent hashing and validation.
|
|
5
|
+
*/
|
|
6
|
+
import { sha256 } from "@noble/hashes/sha256";
|
|
7
|
+
/**
|
|
8
|
+
* Bitcoin script types.
|
|
9
|
+
*/
|
|
10
|
+
export var BitcoinScriptType;
|
|
11
|
+
(function (BitcoinScriptType) {
|
|
12
|
+
BitcoinScriptType[BitcoinScriptType["P2PKH"] = 0] = "P2PKH";
|
|
13
|
+
BitcoinScriptType[BitcoinScriptType["P2WPKH"] = 1] = "P2WPKH";
|
|
14
|
+
BitcoinScriptType[BitcoinScriptType["P2TR"] = 2] = "P2TR";
|
|
15
|
+
})(BitcoinScriptType || (BitcoinScriptType = {}));
|
|
16
|
+
/**
|
|
17
|
+
* Compute double SHA256 (hash256).
|
|
18
|
+
*/
|
|
19
|
+
export function hash256(data) {
|
|
20
|
+
return sha256(sha256(data));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Compute BIP340 tagged hash for Taproot.
|
|
24
|
+
*/
|
|
25
|
+
export function taggedHash(tag, data) {
|
|
26
|
+
const tagHash = sha256(new TextEncoder().encode(tag));
|
|
27
|
+
const combined = new Uint8Array(tagHash.length * 2 + data.length);
|
|
28
|
+
combined.set(tagHash, 0);
|
|
29
|
+
combined.set(tagHash, tagHash.length);
|
|
30
|
+
combined.set(data, tagHash.length * 2);
|
|
31
|
+
return sha256(combined);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Convert hex string to bytes.
|
|
35
|
+
*/
|
|
36
|
+
export function hexToBytes(hex) {
|
|
37
|
+
const cleanHex = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
38
|
+
const bytes = new Uint8Array(cleanHex.length / 2);
|
|
39
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
40
|
+
bytes[i] = parseInt(cleanHex.slice(i * 2, i * 2 + 2), 16);
|
|
41
|
+
}
|
|
42
|
+
return bytes;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Convert bytes to hex string.
|
|
46
|
+
*/
|
|
47
|
+
export function bytesToHex(bytes) {
|
|
48
|
+
return `0x${Array.from(bytes)
|
|
49
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
50
|
+
.join("")}`;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Validate a Bitcoin address format.
|
|
54
|
+
* This is a basic check - full validation requires network context.
|
|
55
|
+
*/
|
|
56
|
+
export function validateBitcoinAddress(address, network = "mainnet") {
|
|
57
|
+
// Bech32/Bech32m addresses
|
|
58
|
+
if (network === "mainnet") {
|
|
59
|
+
if (address.startsWith("bc1q") || address.startsWith("bc1p")) {
|
|
60
|
+
return address.length >= 42 && address.length <= 62;
|
|
61
|
+
}
|
|
62
|
+
// Legacy P2PKH
|
|
63
|
+
if (address.startsWith("1") || address.startsWith("3")) {
|
|
64
|
+
return address.length >= 26 && address.length <= 35;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// Testnet/Signet
|
|
69
|
+
if (address.startsWith("tb1q") || address.startsWith("tb1p")) {
|
|
70
|
+
return address.length >= 42 && address.length <= 62;
|
|
71
|
+
}
|
|
72
|
+
if (address.startsWith("m") || address.startsWith("n") || address.startsWith("2")) {
|
|
73
|
+
return address.length >= 26 && address.length <= 35;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Detect script type from address format.
|
|
80
|
+
*/
|
|
81
|
+
export function detectScriptTypeFromAddress(address) {
|
|
82
|
+
// Taproot (bech32m)
|
|
83
|
+
if (address.startsWith("bc1p") || address.startsWith("tb1p")) {
|
|
84
|
+
return BitcoinScriptType.P2TR;
|
|
85
|
+
}
|
|
86
|
+
// Native SegWit (bech32)
|
|
87
|
+
if (address.startsWith("bc1q") || address.startsWith("tb1q")) {
|
|
88
|
+
return BitcoinScriptType.P2WPKH;
|
|
89
|
+
}
|
|
90
|
+
// Legacy (base58check)
|
|
91
|
+
return BitcoinScriptType.P2PKH;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Compute total input value from parsed PSBT.
|
|
95
|
+
*/
|
|
96
|
+
export function computeTotalInputValue(psbt) {
|
|
97
|
+
return psbt.inputs.reduce((sum, input) => sum + input.value, 0n);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Compute total output value from parsed PSBT.
|
|
101
|
+
*/
|
|
102
|
+
export function computeTotalOutputValue(psbt) {
|
|
103
|
+
return psbt.outputs.reduce((sum, output) => sum + output.value, 0n);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Compute fee from parsed PSBT.
|
|
107
|
+
*/
|
|
108
|
+
export function computeFee(psbt) {
|
|
109
|
+
const totalIn = computeTotalInputValue(psbt);
|
|
110
|
+
const totalOut = computeTotalOutputValue(psbt);
|
|
111
|
+
return totalIn - totalOut;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Format satoshis as BTC string.
|
|
115
|
+
*/
|
|
116
|
+
export function satoshisToBTC(satoshis) {
|
|
117
|
+
const btc = Number(satoshis) / 100_000_000;
|
|
118
|
+
return btc.toFixed(8);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Parse BTC string to satoshis.
|
|
122
|
+
*/
|
|
123
|
+
export function btcToSatoshis(btc) {
|
|
124
|
+
const value = typeof btc === "string" ? parseFloat(btc) : btc;
|
|
125
|
+
return BigInt(Math.round(value * 100_000_000));
|
|
126
|
+
}
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync, writeFileSync, mkdirSync, existsSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { verifyAuditBundle } from "./auditBundle.js";
|
|
6
|
+
import { BackendClient } from "./backend.js";
|
|
7
|
+
import { SKILL_MD, API_REFERENCE_MD, SDK_REFERENCE_MD } from "./skill-templates.js";
|
|
8
|
+
const CONFIG_DIR = join(homedir(), ".kairo");
|
|
9
|
+
const CONFIG_PATH = join(CONFIG_DIR, "config.json");
|
|
10
|
+
function loadConfig() {
|
|
11
|
+
if (!existsSync(CONFIG_PATH))
|
|
12
|
+
return null;
|
|
13
|
+
try {
|
|
14
|
+
return JSON.parse(readFileSync(CONFIG_PATH, "utf8"));
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function requireConfig() {
|
|
21
|
+
const cfg = loadConfig();
|
|
22
|
+
if (!cfg) {
|
|
23
|
+
console.error("No Kairo config found. Run: npx @kairo/sdk init <api-key>");
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
return cfg;
|
|
27
|
+
}
|
|
28
|
+
function getClient(apiKeyOverride) {
|
|
29
|
+
const key = apiKeyOverride ?? requireConfig().apiKey;
|
|
30
|
+
return new BackendClient({ apiKey: key });
|
|
31
|
+
}
|
|
32
|
+
// ── Arg helpers ─────────────────────────────────────────────────────────────
|
|
33
|
+
function flag(args, name) {
|
|
34
|
+
const idx = args.indexOf(name);
|
|
35
|
+
if (idx < 0)
|
|
36
|
+
return undefined;
|
|
37
|
+
return args[idx + 1];
|
|
38
|
+
}
|
|
39
|
+
function requireFlag(args, name, label) {
|
|
40
|
+
const v = flag(args, name);
|
|
41
|
+
if (!v) {
|
|
42
|
+
console.error(`Required: ${name} <${label}>`);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
return v;
|
|
46
|
+
}
|
|
47
|
+
// ── Commands ────────────────────────────────────────────────────────────────
|
|
48
|
+
async function cmdInit(args) {
|
|
49
|
+
const apiKey = args[0];
|
|
50
|
+
if (!apiKey) {
|
|
51
|
+
console.error("Usage: kairo init <api-key>");
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
55
|
+
writeFileSync(CONFIG_PATH, JSON.stringify({ apiKey }, null, 2) + "\n", "utf8");
|
|
56
|
+
console.log(` Config written to ${CONFIG_PATH}`);
|
|
57
|
+
const skillDir = join(process.cwd(), ".cursor", "skills", "kairo");
|
|
58
|
+
const refsDir = join(skillDir, "references");
|
|
59
|
+
mkdirSync(refsDir, { recursive: true });
|
|
60
|
+
writeFileSync(join(skillDir, "SKILL.md"), SKILL_MD, "utf8");
|
|
61
|
+
writeFileSync(join(refsDir, "api.md"), API_REFERENCE_MD, "utf8");
|
|
62
|
+
writeFileSync(join(refsDir, "sdk.md"), SDK_REFERENCE_MD, "utf8");
|
|
63
|
+
console.log(` Skill files installed to ${skillDir}`);
|
|
64
|
+
const client = new BackendClient({ apiKey });
|
|
65
|
+
try {
|
|
66
|
+
await client.getHealth();
|
|
67
|
+
console.log(" Backend connection verified.");
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
console.log(" Warning: could not reach backend (check your network).");
|
|
71
|
+
}
|
|
72
|
+
console.log("\nKairo is ready. Your AI agent can now read the skill at .cursor/skills/kairo/SKILL.md");
|
|
73
|
+
}
|
|
74
|
+
async function cmdHealth() {
|
|
75
|
+
const client = getClient();
|
|
76
|
+
const res = await client.getHealth();
|
|
77
|
+
console.log(JSON.stringify(res, null, 2));
|
|
78
|
+
}
|
|
79
|
+
async function cmdRegister(args) {
|
|
80
|
+
const label = requireFlag(args, "--label", "name");
|
|
81
|
+
const client = getClient();
|
|
82
|
+
const res = await client.register(label);
|
|
83
|
+
console.log(JSON.stringify(res, null, 2));
|
|
84
|
+
}
|
|
85
|
+
async function cmdPolicyCreate(args) {
|
|
86
|
+
const stableId = requireFlag(args, "--stable-id", "id");
|
|
87
|
+
const version = flag(args, "--version") ?? "1.0.0";
|
|
88
|
+
const allowRaw = flag(args, "--allow");
|
|
89
|
+
if (!allowRaw) {
|
|
90
|
+
console.error("Required: --allow <comma-separated addresses>");
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
const addresses = allowRaw.split(",").map((a) => a.trim());
|
|
94
|
+
const rules = addresses.map((addr) => ({ ruleType: 1, params: addr }));
|
|
95
|
+
const client = getClient();
|
|
96
|
+
const res = await client.createPolicyV4({ stableId, version, rules });
|
|
97
|
+
console.log(JSON.stringify(res, null, 2));
|
|
98
|
+
}
|
|
99
|
+
async function cmdPolicyRegister(args) {
|
|
100
|
+
const policyId = requireFlag(args, "--policy-id", "objectId");
|
|
101
|
+
const client = getClient();
|
|
102
|
+
const res = await client.registerPolicyVersionFromPolicy({ policyObjectId: policyId });
|
|
103
|
+
console.log(JSON.stringify(res, null, 2));
|
|
104
|
+
}
|
|
105
|
+
async function cmdPolicyDetails(args) {
|
|
106
|
+
const policyId = requireFlag(args, "--policy-id", "objectId");
|
|
107
|
+
const client = getClient();
|
|
108
|
+
const res = await client.getPolicy(policyId);
|
|
109
|
+
console.log(JSON.stringify(res, null, 2));
|
|
110
|
+
}
|
|
111
|
+
async function cmdVaultStatus(args) {
|
|
112
|
+
const walletId = requireFlag(args, "--wallet-id", "dwalletId");
|
|
113
|
+
const client = getClient();
|
|
114
|
+
const res = await client.getVaultStatus(walletId);
|
|
115
|
+
console.log(JSON.stringify(res, null, 2));
|
|
116
|
+
}
|
|
117
|
+
async function cmdVaultProvision(args) {
|
|
118
|
+
const walletId = requireFlag(args, "--wallet-id", "dwalletId");
|
|
119
|
+
const policyId = requireFlag(args, "--policy-id", "objectId");
|
|
120
|
+
const stableId = requireFlag(args, "--stable-id", "id");
|
|
121
|
+
const client = getClient();
|
|
122
|
+
const res = await client.provision({ dwalletObjectId: walletId, policyObjectId: policyId, stableId });
|
|
123
|
+
console.log(JSON.stringify(res, null, 2));
|
|
124
|
+
}
|
|
125
|
+
async function cmdReceiptMint(args) {
|
|
126
|
+
const policyId = requireFlag(args, "--policy-id", "objectId");
|
|
127
|
+
const bindingId = requireFlag(args, "--binding-id", "objectId");
|
|
128
|
+
const destination = requireFlag(args, "--destination", "hex");
|
|
129
|
+
const intentHash = requireFlag(args, "--intent-hash", "hex");
|
|
130
|
+
const namespace = Number(flag(args, "--namespace") ?? "1");
|
|
131
|
+
const chainId = flag(args, "--chain-id") ?? "0x0aa36a7f";
|
|
132
|
+
const nativeValue = flag(args, "--native-value") ?? ("0x" + "00".repeat(32));
|
|
133
|
+
const client = getClient();
|
|
134
|
+
const res = await client.mintReceipt({
|
|
135
|
+
policyObjectId: policyId,
|
|
136
|
+
bindingObjectId: bindingId,
|
|
137
|
+
namespace,
|
|
138
|
+
chainId,
|
|
139
|
+
intentHashHex: intentHash,
|
|
140
|
+
destinationHex: destination,
|
|
141
|
+
nativeValueHex: nativeValue,
|
|
142
|
+
});
|
|
143
|
+
console.log(JSON.stringify(res, null, 2));
|
|
144
|
+
}
|
|
145
|
+
async function cmdAudit(args) {
|
|
146
|
+
const limit = Number(flag(args, "--limit") ?? "10");
|
|
147
|
+
const client = getClient();
|
|
148
|
+
const res = await client.getAuditEvents(limit);
|
|
149
|
+
console.log(JSON.stringify(res, null, 2));
|
|
150
|
+
}
|
|
151
|
+
async function cmdAuditVerify(args) {
|
|
152
|
+
const suiIdx = args.indexOf("--sui");
|
|
153
|
+
const bundleIdx = args.indexOf("--bundle");
|
|
154
|
+
if (suiIdx < 0 || bundleIdx < 0) {
|
|
155
|
+
console.error("Usage: kairo audit verify --sui <suiRpcUrl> --bundle <path.json>");
|
|
156
|
+
process.exit(2);
|
|
157
|
+
}
|
|
158
|
+
const suiRpcUrl = String(args[suiIdx + 1] ?? "").trim();
|
|
159
|
+
const bundlePath = String(args[bundleIdx + 1] ?? "").trim();
|
|
160
|
+
if (!suiRpcUrl || !bundlePath) {
|
|
161
|
+
console.error("Usage: kairo audit verify --sui <suiRpcUrl> --bundle <path.json>");
|
|
162
|
+
process.exit(2);
|
|
163
|
+
}
|
|
164
|
+
const raw = readFileSync(bundlePath, "utf8");
|
|
165
|
+
const bundle = JSON.parse(raw);
|
|
166
|
+
const res = await verifyAuditBundle({ suiRpcUrl, bundle });
|
|
167
|
+
if (!res.ok) {
|
|
168
|
+
console.error(res.error);
|
|
169
|
+
process.exit(1);
|
|
170
|
+
}
|
|
171
|
+
console.log("OK");
|
|
172
|
+
}
|
|
173
|
+
function printUsage() {
|
|
174
|
+
console.log(`Kairo CLI — Agent Wallet Operations
|
|
175
|
+
|
|
176
|
+
Usage: kairo <command> [options]
|
|
177
|
+
|
|
178
|
+
Setup:
|
|
179
|
+
init <api-key> Store API key + install agent skill files
|
|
180
|
+
|
|
181
|
+
Wallet & Policy:
|
|
182
|
+
health Server health check
|
|
183
|
+
register --label <name> Register new API key
|
|
184
|
+
policy-create --stable-id <id> --allow <addrs> Create policy
|
|
185
|
+
policy-register --policy-id <id> Register policy version
|
|
186
|
+
policy-details --policy-id <id> Get policy details
|
|
187
|
+
vault-status --wallet-id <id> Check vault registration
|
|
188
|
+
vault-provision --wallet-id <id> --policy-id <id> --stable-id <id>
|
|
189
|
+
receipt-mint --policy-id <id> --binding-id <id> --destination <hex> --intent-hash <hex>
|
|
190
|
+
|
|
191
|
+
Utility:
|
|
192
|
+
audit --limit <n> List audit events
|
|
193
|
+
audit verify --sui <url> --bundle <path> Verify audit bundle`);
|
|
194
|
+
}
|
|
195
|
+
// ── Main ────────────────────────────────────────────────────────────────────
|
|
196
|
+
async function main() {
|
|
197
|
+
const args = process.argv.slice(2);
|
|
198
|
+
const cmd = args[0];
|
|
199
|
+
const rest = args.slice(1);
|
|
200
|
+
switch (cmd) {
|
|
201
|
+
case "init":
|
|
202
|
+
return cmdInit(rest);
|
|
203
|
+
case "health":
|
|
204
|
+
return cmdHealth();
|
|
205
|
+
case "register":
|
|
206
|
+
return cmdRegister(rest);
|
|
207
|
+
case "policy-create":
|
|
208
|
+
return cmdPolicyCreate(rest);
|
|
209
|
+
case "policy-register":
|
|
210
|
+
return cmdPolicyRegister(rest);
|
|
211
|
+
case "policy-details":
|
|
212
|
+
return cmdPolicyDetails(rest);
|
|
213
|
+
case "vault-status":
|
|
214
|
+
return cmdVaultStatus(rest);
|
|
215
|
+
case "vault-provision":
|
|
216
|
+
return cmdVaultProvision(rest);
|
|
217
|
+
case "receipt-mint":
|
|
218
|
+
return cmdReceiptMint(rest);
|
|
219
|
+
case "audit":
|
|
220
|
+
if (rest[0] === "verify")
|
|
221
|
+
return cmdAuditVerify(rest.slice(1));
|
|
222
|
+
return cmdAudit(rest);
|
|
223
|
+
case "--help":
|
|
224
|
+
case "-h":
|
|
225
|
+
case undefined:
|
|
226
|
+
printUsage();
|
|
227
|
+
return;
|
|
228
|
+
default:
|
|
229
|
+
console.error(`Unknown command: ${cmd}`);
|
|
230
|
+
printUsage();
|
|
231
|
+
process.exit(1);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
main().catch((e) => {
|
|
235
|
+
console.error(e instanceof Error ? e.message : String(e));
|
|
236
|
+
process.exit(1);
|
|
237
|
+
});
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KairoClient -- the main entry point for agents.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* const kairo = new KairoClient({
|
|
6
|
+
* apiKey: "ka_abc123...",
|
|
7
|
+
* });
|
|
8
|
+
* const wallet = await kairo.createWallet();
|
|
9
|
+
* // { walletId: "0xabc...", address: "0x742d...", curve: "secp256k1" }
|
|
10
|
+
*/
|
|
11
|
+
import { type GovernanceProposalInfo } from "./backend.js";
|
|
12
|
+
import { type SupportedCurve } from "./ika-protocol.js";
|
|
13
|
+
import type { Hex } from "./types.js";
|
|
14
|
+
export interface KairoClientOpts {
|
|
15
|
+
apiKey: string;
|
|
16
|
+
/** Kairo backend URL. Defaults to production if omitted. */
|
|
17
|
+
backendUrl?: string;
|
|
18
|
+
/** Local directory for secret share storage. Defaults to ~/.kairo/keys */
|
|
19
|
+
storePath?: string;
|
|
20
|
+
/** Sui RPC URL for fetching Ika protocol params. Defaults to public testnet. */
|
|
21
|
+
suiRpcUrl?: string;
|
|
22
|
+
/** Sui network. Defaults to "testnet". */
|
|
23
|
+
network?: "testnet" | "mainnet";
|
|
24
|
+
/** Optional chainId -> EVM RPC URL mapping used by signEvm/broadcast/getBalance. */
|
|
25
|
+
evmRpcUrls?: Record<number, string>;
|
|
26
|
+
}
|
|
27
|
+
export interface CreateWalletOpts {
|
|
28
|
+
/** Key curve. Defaults to "secp256k1" (Ethereum). */
|
|
29
|
+
curve?: SupportedCurve;
|
|
30
|
+
/** Policy object ID to bind during provisioning. */
|
|
31
|
+
policyObjectId?: string;
|
|
32
|
+
/** Human-readable label for the binding (derived from policy if omitted). */
|
|
33
|
+
stableId?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface WalletInfo {
|
|
36
|
+
walletId: string;
|
|
37
|
+
address: string;
|
|
38
|
+
curve: string;
|
|
39
|
+
bindingObjectId?: string;
|
|
40
|
+
createdAt: number;
|
|
41
|
+
}
|
|
42
|
+
export interface PresignResult {
|
|
43
|
+
requestId: string;
|
|
44
|
+
presignId: string;
|
|
45
|
+
presignBytes: Uint8Array;
|
|
46
|
+
}
|
|
47
|
+
export interface SignResult {
|
|
48
|
+
requestId: string;
|
|
49
|
+
signId?: string;
|
|
50
|
+
presignId: string;
|
|
51
|
+
signatureHex: Hex;
|
|
52
|
+
}
|
|
53
|
+
export interface SignEvmParams {
|
|
54
|
+
walletId: string;
|
|
55
|
+
to: Hex;
|
|
56
|
+
value: bigint | number | string;
|
|
57
|
+
chainId: number;
|
|
58
|
+
data?: Hex;
|
|
59
|
+
rpcUrl?: string;
|
|
60
|
+
}
|
|
61
|
+
export interface ProposePolicyUpdateParams {
|
|
62
|
+
walletId: string;
|
|
63
|
+
governanceId: string;
|
|
64
|
+
stableId: string;
|
|
65
|
+
version: string;
|
|
66
|
+
expiresAtMs?: number;
|
|
67
|
+
allowNamespaces?: number[];
|
|
68
|
+
allowChainIds?: Array<{
|
|
69
|
+
namespace: number;
|
|
70
|
+
chainId: string;
|
|
71
|
+
}>;
|
|
72
|
+
allowDestinations?: string[];
|
|
73
|
+
denyDestinations?: string[];
|
|
74
|
+
rules: Array<{
|
|
75
|
+
ruleType: number;
|
|
76
|
+
namespace?: number;
|
|
77
|
+
params: string;
|
|
78
|
+
}>;
|
|
79
|
+
registryObjectId?: string;
|
|
80
|
+
note?: string;
|
|
81
|
+
}
|
|
82
|
+
export interface PolicyUpdateProposalResult {
|
|
83
|
+
walletId: string;
|
|
84
|
+
governanceId: string;
|
|
85
|
+
bindingObjectId: string;
|
|
86
|
+
policyObjectId: string;
|
|
87
|
+
policyVersionObjectId: string;
|
|
88
|
+
proposalId: string;
|
|
89
|
+
policyDigest: string;
|
|
90
|
+
registerDigest: string;
|
|
91
|
+
proposalDigest: string;
|
|
92
|
+
}
|
|
93
|
+
export interface ApprovePolicyUpdateParams {
|
|
94
|
+
governanceId: string;
|
|
95
|
+
proposalId: string;
|
|
96
|
+
}
|
|
97
|
+
export interface ExecutePolicyUpdateParams {
|
|
98
|
+
walletId: string;
|
|
99
|
+
governanceId: string;
|
|
100
|
+
proposalId: string;
|
|
101
|
+
}
|
|
102
|
+
export interface PolicyUpdateStatus {
|
|
103
|
+
proposal: GovernanceProposalInfo;
|
|
104
|
+
threshold?: number;
|
|
105
|
+
timelockDurationMs?: number;
|
|
106
|
+
approvalsCollected: number;
|
|
107
|
+
approvalsNeeded?: number;
|
|
108
|
+
state: "awaiting_approvals" | "awaiting_timelock" | "ready_to_execute" | "executed" | "cancelled";
|
|
109
|
+
}
|
|
110
|
+
interface SignPolicyContext {
|
|
111
|
+
namespace: number;
|
|
112
|
+
chainId: number;
|
|
113
|
+
intentHashHex: Hex;
|
|
114
|
+
destinationHex: Hex;
|
|
115
|
+
nativeValue: bigint;
|
|
116
|
+
contextDataHex?: Hex;
|
|
117
|
+
}
|
|
118
|
+
interface SignOpts {
|
|
119
|
+
presignId?: string;
|
|
120
|
+
presignBytes?: Uint8Array;
|
|
121
|
+
policyContext?: SignPolicyContext;
|
|
122
|
+
ethTx?: {
|
|
123
|
+
to: string;
|
|
124
|
+
value: string;
|
|
125
|
+
nonce: number;
|
|
126
|
+
gasLimit: string;
|
|
127
|
+
maxFeePerGas: string;
|
|
128
|
+
maxPriorityFeePerGas: string;
|
|
129
|
+
chainId: number;
|
|
130
|
+
from: string;
|
|
131
|
+
};
|
|
132
|
+
policyVersion?: string;
|
|
133
|
+
}
|
|
134
|
+
export declare class KairoClient {
|
|
135
|
+
private backend;
|
|
136
|
+
private store;
|
|
137
|
+
private suiRpcUrl;
|
|
138
|
+
private network;
|
|
139
|
+
private evmRpcUrls;
|
|
140
|
+
constructor(opts: KairoClientOpts);
|
|
141
|
+
/**
|
|
142
|
+
* Create a new dWallet. Runs DKG on the agent's machine, submits to backend,
|
|
143
|
+
* and optionally provisions the wallet in the vault.
|
|
144
|
+
*
|
|
145
|
+
* The agent's secret share is stored locally and never sent to the server.
|
|
146
|
+
*/
|
|
147
|
+
createWallet(opts?: CreateWalletOpts): Promise<WalletInfo>;
|
|
148
|
+
/** List all wallets in local key store. */
|
|
149
|
+
listWallets(): WalletInfo[];
|
|
150
|
+
/** Get a wallet from local key store by ID. */
|
|
151
|
+
getWallet(walletId: string): WalletInfo | null;
|
|
152
|
+
/**
|
|
153
|
+
* Governance-first policy update: creates a new policy + version, then proposes
|
|
154
|
+
* a change for approvers. This method does NOT execute/reaffirm directly.
|
|
155
|
+
*/
|
|
156
|
+
updatePolicy(params: ProposePolicyUpdateParams): Promise<PolicyUpdateProposalResult>;
|
|
157
|
+
/**
|
|
158
|
+
* Create and register a new policy version, then create governance proposal.
|
|
159
|
+
* This is the safe default for agents so policy changes require approvers.
|
|
160
|
+
*/
|
|
161
|
+
proposePolicyUpdate(params: ProposePolicyUpdateParams): Promise<PolicyUpdateProposalResult>;
|
|
162
|
+
approvePolicyUpdate(params: ApprovePolicyUpdateParams): Promise<{
|
|
163
|
+
digest: string;
|
|
164
|
+
}>;
|
|
165
|
+
executePolicyUpdate(params: ExecutePolicyUpdateParams): Promise<{
|
|
166
|
+
digest: string;
|
|
167
|
+
}>;
|
|
168
|
+
getPolicyUpdateStatus(proposalId: string): Promise<PolicyUpdateStatus>;
|
|
169
|
+
getPolicy(walletId: string): Promise<Record<string, unknown>>;
|
|
170
|
+
createPresign(walletId: string): Promise<PresignResult>;
|
|
171
|
+
sign(walletId: string, messageHex: string, opts?: SignOpts): Promise<SignResult>;
|
|
172
|
+
signEvm(params: SignEvmParams): Promise<Hex>;
|
|
173
|
+
broadcastEvm(signedTx: Hex, rpcUrl: string): Promise<Hex>;
|
|
174
|
+
getBalance(address: Hex, rpcUrl: string): Promise<bigint>;
|
|
175
|
+
private activateWallet;
|
|
176
|
+
private pollDKGStatus;
|
|
177
|
+
private requireWalletRecord;
|
|
178
|
+
private pollPresignStatus;
|
|
179
|
+
private pollSignStatus;
|
|
180
|
+
private mintPolicyReceipt;
|
|
181
|
+
private computeUserSignMessageWithExtensionFallback;
|
|
182
|
+
private rebuildSigningMaterialFromChain;
|
|
183
|
+
private resolveEvmRpcUrl;
|
|
184
|
+
private evmRpcCall;
|
|
185
|
+
}
|
|
186
|
+
export {};
|