@rebelfi/agent-sdk 1.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 +337 -0
- package/dist/amount-utils.d.ts +9 -0
- package/dist/amount-utils.js +80 -0
- package/dist/amount-utils.js.map +1 -0
- package/dist/cjs/amount-utils.js +87 -0
- package/dist/cjs/amount-utils.js.map +1 -0
- package/dist/cjs/cli.js +189 -0
- package/dist/cjs/cli.js.map +1 -0
- package/dist/cjs/client.js +49 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/commands/account.js +250 -0
- package/dist/cjs/commands/account.js.map +1 -0
- package/dist/cjs/commands/auth.js +78 -0
- package/dist/cjs/commands/auth.js.map +1 -0
- package/dist/cjs/commands/balance.js +15 -0
- package/dist/cjs/commands/balance.js.map +1 -0
- package/dist/cjs/commands/cancel.js +34 -0
- package/dist/cjs/commands/cancel.js.map +1 -0
- package/dist/cjs/commands/chat.js +15 -0
- package/dist/cjs/commands/chat.js.map +1 -0
- package/dist/cjs/commands/claim.js +34 -0
- package/dist/cjs/commands/claim.js.map +1 -0
- package/dist/cjs/commands/config.js +29 -0
- package/dist/cjs/commands/config.js.map +1 -0
- package/dist/cjs/commands/contacts.js +29 -0
- package/dist/cjs/commands/contacts.js.map +1 -0
- package/dist/cjs/commands/init.js +43 -0
- package/dist/cjs/commands/init.js.map +1 -0
- package/dist/cjs/commands/orders.js +167 -0
- package/dist/cjs/commands/orders.js.map +1 -0
- package/dist/cjs/commands/pay.js +41 -0
- package/dist/cjs/commands/pay.js.map +1 -0
- package/dist/cjs/commands/payments.js +27 -0
- package/dist/cjs/commands/payments.js.map +1 -0
- package/dist/cjs/commands/wallet.js +69 -0
- package/dist/cjs/commands/wallet.js.map +1 -0
- package/dist/cjs/config.js +91 -0
- package/dist/cjs/config.js.map +1 -0
- package/dist/cjs/contacts.js +87 -0
- package/dist/cjs/contacts.js.map +1 -0
- package/dist/cjs/errors.js +93 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.js +64 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/intent/chains.js +29 -0
- package/dist/cjs/intent/chains.js.map +1 -0
- package/dist/cjs/intent/constraints.js +46 -0
- package/dist/cjs/intent/constraints.js.map +1 -0
- package/dist/cjs/intent/helpers.js +34 -0
- package/dist/cjs/intent/helpers.js.map +1 -0
- package/dist/cjs/intent/index.js +99 -0
- package/dist/cjs/intent/index.js.map +1 -0
- package/dist/cjs/intent/matcher.js +119 -0
- package/dist/cjs/intent/matcher.js.map +1 -0
- package/dist/cjs/intent/program-registry.js +68 -0
- package/dist/cjs/intent/program-registry.js.map +1 -0
- package/dist/cjs/intent/token-registry.js +99 -0
- package/dist/cjs/intent/token-registry.js.map +1 -0
- package/dist/cjs/intent/types.js +3 -0
- package/dist/cjs/intent/types.js.map +1 -0
- package/dist/cjs/orders/evaluate.js +168 -0
- package/dist/cjs/orders/evaluate.js.map +1 -0
- package/dist/cjs/orders/index.js +14 -0
- package/dist/cjs/orders/index.js.map +1 -0
- package/dist/cjs/orders/store.js +47 -0
- package/dist/cjs/orders/store.js.map +1 -0
- package/dist/cjs/orders/sugar.js +35 -0
- package/dist/cjs/orders/sugar.js.map +1 -0
- package/dist/cjs/orders/types.js +3 -0
- package/dist/cjs/orders/types.js.map +1 -0
- package/dist/cjs/output.js +47 -0
- package/dist/cjs/output.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/transfers.js +15 -0
- package/dist/cjs/transfers.js.map +1 -0
- package/dist/cjs/validate.js +77 -0
- package/dist/cjs/validate.js.map +1 -0
- package/dist/cjs/verify/decoders/ata.js +19 -0
- package/dist/cjs/verify/decoders/ata.js.map +1 -0
- package/dist/cjs/verify/decoders/compute-budget.js +32 -0
- package/dist/cjs/verify/decoders/compute-budget.js.map +1 -0
- package/dist/cjs/verify/decoders/handshake.js +180 -0
- package/dist/cjs/verify/decoders/handshake.js.map +1 -0
- package/dist/cjs/verify/decoders/jupiter.js +39 -0
- package/dist/cjs/verify/decoders/jupiter.js.map +1 -0
- package/dist/cjs/verify/decoders/memo.js +12 -0
- package/dist/cjs/verify/decoders/memo.js.map +1 -0
- package/dist/cjs/verify/decoders/silkysig.js +162 -0
- package/dist/cjs/verify/decoders/silkysig.js.map +1 -0
- package/dist/cjs/verify/decoders/spl-token.js +125 -0
- package/dist/cjs/verify/decoders/spl-token.js.map +1 -0
- package/dist/cjs/verify/decoders/system.js +87 -0
- package/dist/cjs/verify/decoders/system.js.map +1 -0
- package/dist/cjs/verify/flags.js +87 -0
- package/dist/cjs/verify/flags.js.map +1 -0
- package/dist/cjs/verify/index.js +384 -0
- package/dist/cjs/verify/index.js.map +1 -0
- package/dist/cjs/verify/registry.js +24 -0
- package/dist/cjs/verify/registry.js.map +1 -0
- package/dist/cjs/verify/rpc.js +52 -0
- package/dist/cjs/verify/rpc.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +224 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.js +43 -0
- package/dist/client.js.map +1 -0
- package/dist/commands/account.d.ts +21 -0
- package/dist/commands/account.js +239 -0
- package/dist/commands/account.js.map +1 -0
- package/dist/commands/auth.d.ts +5 -0
- package/dist/commands/auth.js +70 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/balance.d.ts +3 -0
- package/dist/commands/balance.js +12 -0
- package/dist/commands/balance.js.map +1 -0
- package/dist/commands/cancel.d.ts +3 -0
- package/dist/commands/cancel.js +28 -0
- package/dist/commands/cancel.js.map +1 -0
- package/dist/commands/chat.d.ts +1 -0
- package/dist/commands/chat.js +12 -0
- package/dist/commands/chat.js.map +1 -0
- package/dist/commands/claim.d.ts +3 -0
- package/dist/commands/claim.js +28 -0
- package/dist/commands/claim.js.map +1 -0
- package/dist/commands/config.d.ts +3 -0
- package/dist/commands/config.js +24 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/contacts.d.ts +4 -0
- package/dist/commands/contacts.js +23 -0
- package/dist/commands/contacts.js.map +1 -0
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/init.js +37 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/orders.d.ts +19 -0
- package/dist/commands/orders.js +157 -0
- package/dist/commands/orders.js.map +1 -0
- package/dist/commands/pay.d.ts +4 -0
- package/dist/commands/pay.js +35 -0
- package/dist/commands/pay.js.map +1 -0
- package/dist/commands/payments.d.ts +4 -0
- package/dist/commands/payments.js +23 -0
- package/dist/commands/payments.js.map +1 -0
- package/dist/commands/wallet.d.ts +7 -0
- package/dist/commands/wallet.js +61 -0
- package/dist/commands/wallet.js.map +1 -0
- package/dist/config.d.ts +40 -0
- package/dist/config.js +74 -0
- package/dist/config.js.map +1 -0
- package/dist/contacts.d.ts +15 -0
- package/dist/contacts.js +74 -0
- package/dist/contacts.js.map +1 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.js +87 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/intent/chains.d.ts +7 -0
- package/dist/intent/chains.js +24 -0
- package/dist/intent/chains.js.map +1 -0
- package/dist/intent/constraints.d.ts +8 -0
- package/dist/intent/constraints.js +43 -0
- package/dist/intent/constraints.js.map +1 -0
- package/dist/intent/helpers.d.ts +6 -0
- package/dist/intent/helpers.js +27 -0
- package/dist/intent/helpers.js.map +1 -0
- package/dist/intent/index.d.ts +11 -0
- package/dist/intent/index.js +87 -0
- package/dist/intent/index.js.map +1 -0
- package/dist/intent/matcher.d.ts +8 -0
- package/dist/intent/matcher.js +116 -0
- package/dist/intent/matcher.js.map +1 -0
- package/dist/intent/program-registry.d.ts +13 -0
- package/dist/intent/program-registry.js +65 -0
- package/dist/intent/program-registry.js.map +1 -0
- package/dist/intent/token-registry.d.ts +17 -0
- package/dist/intent/token-registry.js +96 -0
- package/dist/intent/token-registry.js.map +1 -0
- package/dist/intent/types.d.ts +89 -0
- package/dist/intent/types.js +2 -0
- package/dist/intent/types.js.map +1 -0
- package/dist/orders/evaluate.d.ts +28 -0
- package/dist/orders/evaluate.js +165 -0
- package/dist/orders/evaluate.js.map +1 -0
- package/dist/orders/index.d.ts +7 -0
- package/dist/orders/index.js +4 -0
- package/dist/orders/index.js.map +1 -0
- package/dist/orders/store.d.ts +9 -0
- package/dist/orders/store.js +37 -0
- package/dist/orders/store.js.map +1 -0
- package/dist/orders/sugar.d.ts +13 -0
- package/dist/orders/sugar.js +32 -0
- package/dist/orders/sugar.js.map +1 -0
- package/dist/orders/types.d.ts +37 -0
- package/dist/orders/types.js +2 -0
- package/dist/orders/types.js.map +1 -0
- package/dist/output.d.ts +4 -0
- package/dist/output.js +42 -0
- package/dist/output.js.map +1 -0
- package/dist/transfers.d.ts +32 -0
- package/dist/transfers.js +12 -0
- package/dist/transfers.js.map +1 -0
- package/dist/validate.d.ts +8 -0
- package/dist/validate.js +69 -0
- package/dist/validate.js.map +1 -0
- package/dist/verify/decoders/ata.d.ts +5 -0
- package/dist/verify/decoders/ata.js +16 -0
- package/dist/verify/decoders/ata.js.map +1 -0
- package/dist/verify/decoders/compute-budget.d.ts +5 -0
- package/dist/verify/decoders/compute-budget.js +29 -0
- package/dist/verify/decoders/compute-budget.js.map +1 -0
- package/dist/verify/decoders/handshake.d.ts +5 -0
- package/dist/verify/decoders/handshake.js +177 -0
- package/dist/verify/decoders/handshake.js.map +1 -0
- package/dist/verify/decoders/jupiter.d.ts +5 -0
- package/dist/verify/decoders/jupiter.js +36 -0
- package/dist/verify/decoders/jupiter.js.map +1 -0
- package/dist/verify/decoders/memo.d.ts +5 -0
- package/dist/verify/decoders/memo.js +9 -0
- package/dist/verify/decoders/memo.js.map +1 -0
- package/dist/verify/decoders/silkysig.d.ts +5 -0
- package/dist/verify/decoders/silkysig.js +159 -0
- package/dist/verify/decoders/silkysig.js.map +1 -0
- package/dist/verify/decoders/spl-token.d.ts +5 -0
- package/dist/verify/decoders/spl-token.js +122 -0
- package/dist/verify/decoders/spl-token.js.map +1 -0
- package/dist/verify/decoders/system.d.ts +5 -0
- package/dist/verify/decoders/system.js +84 -0
- package/dist/verify/decoders/system.js.map +1 -0
- package/dist/verify/flags.d.ts +3 -0
- package/dist/verify/flags.js +83 -0
- package/dist/verify/flags.js.map +1 -0
- package/dist/verify/index.d.ts +75 -0
- package/dist/verify/index.js +380 -0
- package/dist/verify/index.js.map +1 -0
- package/dist/verify/registry.d.ts +13 -0
- package/dist/verify/registry.js +21 -0
- package/dist/verify/registry.js.map +1 -0
- package/dist/verify/rpc.d.ts +14 -0
- package/dist/verify/rpc.js +48 -0
- package/dist/verify/rpc.js.map +1 -0
- package/package.json +85 -0
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare const CONFIG_DIR: string;
|
|
2
|
+
export interface WalletEntry {
|
|
3
|
+
label: string;
|
|
4
|
+
address: string;
|
|
5
|
+
privateKey: string;
|
|
6
|
+
}
|
|
7
|
+
export interface AccountInfo {
|
|
8
|
+
pda: string;
|
|
9
|
+
owner: string;
|
|
10
|
+
mint: string;
|
|
11
|
+
mintDecimals: number;
|
|
12
|
+
operatorIndex: number;
|
|
13
|
+
perTxLimit: number;
|
|
14
|
+
syncedAt: string;
|
|
15
|
+
}
|
|
16
|
+
export type SolanaCluster = 'mainnet-beta' | 'devnet';
|
|
17
|
+
export interface SilkConfig {
|
|
18
|
+
wallets: WalletEntry[];
|
|
19
|
+
defaultWallet: string;
|
|
20
|
+
preferences: Record<string, unknown>;
|
|
21
|
+
apiUrl?: string;
|
|
22
|
+
cluster?: SolanaCluster;
|
|
23
|
+
account?: AccountInfo;
|
|
24
|
+
agentId?: string;
|
|
25
|
+
apiKey?: string;
|
|
26
|
+
}
|
|
27
|
+
export declare function loadConfig(): SilkConfig;
|
|
28
|
+
export declare function saveConfig(config: SilkConfig): void;
|
|
29
|
+
export declare function getWallet(config: SilkConfig, label?: string): WalletEntry;
|
|
30
|
+
export declare function getCluster(config: SilkConfig): SolanaCluster;
|
|
31
|
+
export declare function getApiUrl(config: SilkConfig): string;
|
|
32
|
+
export declare function ensureAgentId(config: SilkConfig): {
|
|
33
|
+
agentId: string;
|
|
34
|
+
created: boolean;
|
|
35
|
+
};
|
|
36
|
+
export declare function getClaimUrl(config: SilkConfig, transferPda: string): string;
|
|
37
|
+
export declare function getSetupUrl(config: SilkConfig, agentAddress: string): string;
|
|
38
|
+
export declare function getAgentId(config: SilkConfig): string;
|
|
39
|
+
export declare function getApiKey(config: SilkConfig): string | undefined;
|
|
40
|
+
export declare function clearApiKey(config: SilkConfig): void;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
5
|
+
import { SdkError } from './errors.js';
|
|
6
|
+
export const CONFIG_DIR = path.join(os.homedir(), '.config', 'silkyway');
|
|
7
|
+
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
8
|
+
function defaultConfig() {
|
|
9
|
+
return { wallets: [], defaultWallet: 'main', preferences: {}, cluster: 'mainnet-beta' };
|
|
10
|
+
}
|
|
11
|
+
export function loadConfig() {
|
|
12
|
+
try {
|
|
13
|
+
const raw = fs.readFileSync(CONFIG_FILE, 'utf-8');
|
|
14
|
+
return JSON.parse(raw);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return defaultConfig();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function saveConfig(config) {
|
|
21
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
22
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), 'utf-8');
|
|
23
|
+
}
|
|
24
|
+
export function getWallet(config, label) {
|
|
25
|
+
const target = label || config.defaultWallet;
|
|
26
|
+
const wallet = config.wallets.find((w) => w.label === target);
|
|
27
|
+
if (!wallet) {
|
|
28
|
+
throw new SdkError('WALLET_NOT_FOUND', `Wallet "${target}" not found. Run: silky wallet create`);
|
|
29
|
+
}
|
|
30
|
+
return wallet;
|
|
31
|
+
}
|
|
32
|
+
const CLUSTER_API_URLS = {
|
|
33
|
+
'mainnet-beta': 'https://api.silkyway.ai',
|
|
34
|
+
'devnet': 'https://devnet-api.silkyway.ai',
|
|
35
|
+
};
|
|
36
|
+
export function getCluster(config) {
|
|
37
|
+
return config.cluster || 'mainnet-beta';
|
|
38
|
+
}
|
|
39
|
+
export function getApiUrl(config) {
|
|
40
|
+
return config.apiUrl || process.env.SILKY_API_URL || CLUSTER_API_URLS[getCluster(config)];
|
|
41
|
+
}
|
|
42
|
+
export function ensureAgentId(config) {
|
|
43
|
+
if (config.agentId) {
|
|
44
|
+
return { agentId: config.agentId, created: false };
|
|
45
|
+
}
|
|
46
|
+
const agentId = randomUUID();
|
|
47
|
+
config.agentId = agentId;
|
|
48
|
+
return { agentId, created: true };
|
|
49
|
+
}
|
|
50
|
+
const APP_BASE_URL = 'https://app.silkyway.ai';
|
|
51
|
+
export function getClaimUrl(config, transferPda) {
|
|
52
|
+
const base = `${APP_BASE_URL}/transfers/${transferPda}`;
|
|
53
|
+
const cluster = getCluster(config);
|
|
54
|
+
return cluster === 'devnet' ? `${base}?cluster=devnet` : base;
|
|
55
|
+
}
|
|
56
|
+
export function getSetupUrl(config, agentAddress) {
|
|
57
|
+
const base = `${APP_BASE_URL}/account/setup?agent=${agentAddress}`;
|
|
58
|
+
const cluster = getCluster(config);
|
|
59
|
+
return cluster === 'devnet' ? `${base}&cluster=devnet` : base;
|
|
60
|
+
}
|
|
61
|
+
export function getAgentId(config) {
|
|
62
|
+
const result = ensureAgentId(config);
|
|
63
|
+
if (result.created) {
|
|
64
|
+
saveConfig(config);
|
|
65
|
+
}
|
|
66
|
+
return result.agentId;
|
|
67
|
+
}
|
|
68
|
+
export function getApiKey(config) {
|
|
69
|
+
return config.apiKey || process.env.SILKY_API_KEY;
|
|
70
|
+
}
|
|
71
|
+
export function clearApiKey(config) {
|
|
72
|
+
delete config.apiKey;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AACzE,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AA+BzD,SAAS,aAAa;IACpB,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;AAC1F,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAClD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAe,CAAC;IACvC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,aAAa,EAAE,CAAC;IACzB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAkB;IAC3C,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9C,EAAE,CAAC,aAAa,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC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AU,WAAW,CAAC,MAAkB,EAAE,WAAmB;IACjE,MAAM,IAAI,GAAG,GAAG,YAAY,cAAc,WAAW,EAAE,CAAC;IACxD,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IACnC,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAkB,EAAE,YAAoB;IAClE,MAAM,IAAI,GAAG,GAAG,YAAY,wBAAwB,YAAY,EAAE,CAAC;IACnE,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IACnC,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAkB;IAC3C,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACrC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,UAAU,CAAC,MAAM,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,MAAM,CAAC,OAAO,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,MAAkB;IAC1C,OAAO,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAkB;IAC5C,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface Contact {
|
|
2
|
+
name: string;
|
|
3
|
+
address: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ContactsStore {
|
|
6
|
+
contacts: Contact[];
|
|
7
|
+
}
|
|
8
|
+
export declare function loadContacts(): ContactsStore;
|
|
9
|
+
export declare function saveContacts(store: ContactsStore): void;
|
|
10
|
+
export declare function addContact(name: string, address: string): void;
|
|
11
|
+
export declare function removeContact(name: string): void;
|
|
12
|
+
export declare function getContact(name: string): Contact | null;
|
|
13
|
+
export declare function listContacts(): Contact[];
|
|
14
|
+
export declare function resolveRecipient(recipient: string): string;
|
|
15
|
+
export declare function initContacts(): boolean;
|
package/dist/contacts.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { PublicKey } from '@solana/web3.js';
|
|
4
|
+
import { CONFIG_DIR } from './config.js';
|
|
5
|
+
import { SdkError } from './errors.js';
|
|
6
|
+
const CONTACTS_FILE = path.join(CONFIG_DIR, 'contacts.json');
|
|
7
|
+
export function loadContacts() {
|
|
8
|
+
try {
|
|
9
|
+
const raw = fs.readFileSync(CONTACTS_FILE, 'utf-8');
|
|
10
|
+
return JSON.parse(raw);
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return { contacts: [] };
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function saveContacts(store) {
|
|
17
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
18
|
+
fs.writeFileSync(CONTACTS_FILE, JSON.stringify(store, null, 2), 'utf-8');
|
|
19
|
+
}
|
|
20
|
+
function isValidSolanaAddress(address) {
|
|
21
|
+
try {
|
|
22
|
+
new PublicKey(address);
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function addContact(name, address) {
|
|
30
|
+
const normalized = name.toLowerCase();
|
|
31
|
+
if (isValidSolanaAddress(normalized)) {
|
|
32
|
+
throw new SdkError('INVALID_CONTACT_NAME', 'Contact name cannot be a valid Solana address');
|
|
33
|
+
}
|
|
34
|
+
if (!isValidSolanaAddress(address)) {
|
|
35
|
+
throw new SdkError('INVALID_ADDRESS', `"${address}" is not a valid Solana address`);
|
|
36
|
+
}
|
|
37
|
+
const store = loadContacts();
|
|
38
|
+
const existing = store.contacts.find((c) => c.name === normalized);
|
|
39
|
+
if (existing) {
|
|
40
|
+
throw new SdkError('CONTACT_EXISTS', `Contact "${normalized}" already exists (${existing.address})`);
|
|
41
|
+
}
|
|
42
|
+
store.contacts.push({ name: normalized, address });
|
|
43
|
+
saveContacts(store);
|
|
44
|
+
}
|
|
45
|
+
export function removeContact(name) {
|
|
46
|
+
const normalized = name.toLowerCase();
|
|
47
|
+
const store = loadContacts();
|
|
48
|
+
const index = store.contacts.findIndex((c) => c.name === normalized);
|
|
49
|
+
if (index === -1) {
|
|
50
|
+
throw new SdkError('CONTACT_NOT_FOUND', `Contact "${normalized}" not found`);
|
|
51
|
+
}
|
|
52
|
+
store.contacts.splice(index, 1);
|
|
53
|
+
saveContacts(store);
|
|
54
|
+
}
|
|
55
|
+
export function getContact(name) {
|
|
56
|
+
const normalized = name.toLowerCase();
|
|
57
|
+
const store = loadContacts();
|
|
58
|
+
return store.contacts.find((c) => c.name === normalized) || null;
|
|
59
|
+
}
|
|
60
|
+
export function listContacts() {
|
|
61
|
+
return loadContacts().contacts;
|
|
62
|
+
}
|
|
63
|
+
export function resolveRecipient(recipient) {
|
|
64
|
+
const contact = getContact(recipient);
|
|
65
|
+
return contact ? contact.address : recipient;
|
|
66
|
+
}
|
|
67
|
+
export function initContacts() {
|
|
68
|
+
if (fs.existsSync(CONTACTS_FILE)) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
saveContacts({ contacts: [] });
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=contacts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contacts.js","sourceRoot":"","sources":["../src/contacts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;A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CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC,IAAI,IAAI,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,OAAO,YAAY,EAAE,CAAC,QAAQ,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,SAAiB;IAChD,MAAM,OAAO,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;IACtC,OAAO,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,IAAI,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;QACjC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,YAAY,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;IAC/B,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class SdkError extends Error {
|
|
2
|
+
readonly code: string;
|
|
3
|
+
constructor(code: string, message: string);
|
|
4
|
+
}
|
|
5
|
+
export declare const ANCHOR_ERROR_MAP: Record<number, {
|
|
6
|
+
code: string;
|
|
7
|
+
message: string;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const SILKYSIG_ERROR_MAP: Record<number, {
|
|
10
|
+
code: string;
|
|
11
|
+
message: string;
|
|
12
|
+
}>;
|
|
13
|
+
export declare function toSilkysigError(err: unknown): SdkError;
|
|
14
|
+
export declare function toSdkError(err: unknown): SdkError;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export class SdkError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
constructor(code, message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.code = code;
|
|
6
|
+
this.name = 'SdkError';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export const ANCHOR_ERROR_MAP = {
|
|
10
|
+
6000: { code: 'ANCHOR_MATH_OVERFLOW', message: 'Mathematical overflow occurred' },
|
|
11
|
+
6001: { code: 'ANCHOR_TRANSFER_NOT_ACTIVE', message: 'Transfer is not in active status' },
|
|
12
|
+
6002: { code: 'ANCHOR_CANNOT_CLAIM', message: 'Claim deadline has passed' },
|
|
13
|
+
6003: { code: 'ANCHOR_CONDITIONS_NOT_MET', message: 'Release conditions not met' },
|
|
14
|
+
6004: { code: 'ANCHOR_INVALID_CONDITION', message: 'Invalid condition parameters' },
|
|
15
|
+
6005: { code: 'ANCHOR_INSUFFICIENT_FUNDS', message: 'Insufficient funds in vault' },
|
|
16
|
+
6006: { code: 'ANCHOR_POOL_PAUSED', message: 'Pool is paused' },
|
|
17
|
+
6007: { code: 'ANCHOR_UNAUTHORIZED', message: 'Unauthorized action' },
|
|
18
|
+
6008: { code: 'ANCHOR_INVALID_TIME_WINDOW', message: 'Invalid time window' },
|
|
19
|
+
6009: { code: 'ANCHOR_DEPOSIT_TOO_SMALL', message: 'Deposit amount too small' },
|
|
20
|
+
6010: { code: 'ANCHOR_INVALID_FEE_CONFIG', message: 'Invalid fee configuration' },
|
|
21
|
+
6011: { code: 'ANCHOR_INVALID_TRANSFER_FEE', message: 'Invalid transfer fee' },
|
|
22
|
+
6012: { code: 'ANCHOR_TRANSFER_ALREADY_CLAIMED', message: 'Transfer already claimed' },
|
|
23
|
+
6013: { code: 'ANCHOR_TRANSFER_ALREADY_CANCELLED', message: 'Transfer already cancelled' },
|
|
24
|
+
6014: { code: 'ANCHOR_TRANSFER_ALREADY_REJECTED', message: 'Transfer already rejected' },
|
|
25
|
+
6015: { code: 'ANCHOR_TRANSFER_EXPIRED', message: 'Transfer is expired' },
|
|
26
|
+
6016: { code: 'ANCHOR_ONLY_SENDER_CAN_CANCEL', message: 'Only sender can cancel transfer' },
|
|
27
|
+
6017: { code: 'ANCHOR_ONLY_RECIPIENT_CAN_CLAIM', message: 'Only recipient can claim transfer' },
|
|
28
|
+
6018: { code: 'ANCHOR_ONLY_OPERATOR_CAN_REJECT', message: 'Only operator can reject transfer' },
|
|
29
|
+
6019: { code: 'ANCHOR_INVALID_MEMO_LENGTH', message: 'Invalid memo length' },
|
|
30
|
+
6020: { code: 'ANCHOR_CLAIM_DEADLINE_NOT_PASSED', message: 'Claim deadline has not passed' },
|
|
31
|
+
6021: { code: 'ANCHOR_CALCULATION_ERROR', message: 'Calculation error' },
|
|
32
|
+
6022: { code: 'ANCHOR_MISSING_ACCOUNT', message: 'Missing required account' },
|
|
33
|
+
6023: { code: 'ANCHOR_INVALID_MINT', message: 'Invalid mint' },
|
|
34
|
+
6024: { code: 'ANCHOR_STALE_POOL_VALUE', message: 'Pool value is stale and must be updated' },
|
|
35
|
+
6025: { code: 'ANCHOR_INVALID_OPERATION', message: 'Invalid operation for this pool type' },
|
|
36
|
+
6026: { code: 'ANCHOR_OUTSTANDING_TRANSFERS', message: 'Cannot reset pool with outstanding transfers' },
|
|
37
|
+
6027: { code: 'ANCHOR_INVALID_TRANSFER', message: 'Invalid transfer' },
|
|
38
|
+
6028: { code: 'ANCHOR_TRANSFER_ALREADY_DECLINED', message: 'Transfer already declined' },
|
|
39
|
+
6029: { code: 'ANCHOR_ONLY_RECIPIENT_CAN_DECLINE', message: 'Only recipient can decline transfer' },
|
|
40
|
+
};
|
|
41
|
+
export const SILKYSIG_ERROR_MAP = {
|
|
42
|
+
6000: { code: 'POLICY_UNAUTHORIZED', message: 'Unauthorized: signer is not owner or operator' },
|
|
43
|
+
6001: { code: 'POLICY_EXCEEDS_TX_LIMIT', message: 'Transfer exceeds operator per-transaction limit' },
|
|
44
|
+
6002: { code: 'ACCOUNT_PAUSED', message: 'Account is paused' },
|
|
45
|
+
6003: { code: 'MAX_OPERATORS', message: 'Maximum operators reached' },
|
|
46
|
+
6004: { code: 'OPERATOR_NOT_FOUND', message: 'Operator not found' },
|
|
47
|
+
6005: { code: 'OPERATOR_EXISTS', message: 'Operator slot already occupied' },
|
|
48
|
+
6006: { code: 'MATH_OVERFLOW', message: 'Mathematical overflow' },
|
|
49
|
+
6007: { code: 'AMOUNT_MUST_BE_POSITIVE', message: 'Amount must be positive' },
|
|
50
|
+
6008: { code: 'DRIFT_USER_ALREADY_INITIALIZED', message: 'Drift user already initialized' },
|
|
51
|
+
6009: { code: 'DRIFT_DEPOSIT_FAILED', message: 'Drift deposit failed' },
|
|
52
|
+
6010: { code: 'DRIFT_WITHDRAW_FAILED', message: 'Drift withdrawal failed' },
|
|
53
|
+
6011: { code: 'INVALID_DRIFT_USER', message: 'Invalid Drift user account' },
|
|
54
|
+
6012: { code: 'MISSING_DRIFT_ACCOUNTS', message: 'Missing required Drift accounts' },
|
|
55
|
+
6013: { code: 'INVALID_DRIFT_PROGRAM', message: 'Invalid Drift program ID' },
|
|
56
|
+
6014: { code: 'DRIFT_DELETE_USER_FAILED', message: 'Failed to delete Drift user' },
|
|
57
|
+
};
|
|
58
|
+
export function toSilkysigError(err) {
|
|
59
|
+
if (err instanceof SdkError)
|
|
60
|
+
return err;
|
|
61
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
62
|
+
const hexMatch = message.match(/0x([0-9a-fA-F]+)/);
|
|
63
|
+
if (hexMatch) {
|
|
64
|
+
const errorCode = parseInt(hexMatch[1], 16);
|
|
65
|
+
const mapped = SILKYSIG_ERROR_MAP[errorCode];
|
|
66
|
+
if (mapped) {
|
|
67
|
+
return new SdkError(mapped.code, mapped.message);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return new SdkError('UNKNOWN_ERROR', message);
|
|
71
|
+
}
|
|
72
|
+
export function toSdkError(err) {
|
|
73
|
+
if (err instanceof SdkError)
|
|
74
|
+
return err;
|
|
75
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
76
|
+
// Parse Anchor hex error codes from simulation messages (e.g. "0x1770")
|
|
77
|
+
const hexMatch = message.match(/0x([0-9a-fA-F]+)/);
|
|
78
|
+
if (hexMatch) {
|
|
79
|
+
const errorCode = parseInt(hexMatch[1], 16);
|
|
80
|
+
const anchor = ANCHOR_ERROR_MAP[errorCode];
|
|
81
|
+
if (anchor) {
|
|
82
|
+
return new SdkError(anchor.code, anchor.message);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return new SdkError('UNKNOWN_ERROR', message);
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,QAAS,SAAQ,KAAK;IAEf;IADlB,YACkB,IAAY,EAC5B,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,SAAI,GAAJ,IAAI,CAAQ;QAI5B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAsD;IACjF,IAAI,EAAE,EAAE,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,gCAAgC,EAAE;IACjF,IAAI,EAAE,EAAE,IAAI,EAAE,4BAA4B,EAAE,OAAO,EAAE,kCAAkC,EAAE;IACzF,IAAI,EAAE,EAAE,IAAI,EAAE,qBAAqB,EAAE,OAAO,EAAE,2BAA2B,EAAE;IAC3E,IAAI,EAAE,EAAE,IAAI,EAAE,2BAA2B,EAAE,OAAO,EAAE,4BAA4B,EAAE;IAClF,IAAI,EAAE,EAAE,IAAI,EAAE,0BAA0B,EAAE,OAAO,EAAE,8BAA8B,EAAE;IACnF,IAAI,EAAE,EAAE,IAAI,EAAE,2BAA2B,EAAE,OAAO,EAAE,6BAA6B,EAAE;IACnF,IAAI,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,OAAO,EAAE,gBAAgB,EAAE;IAC/D,IAAI,EAAE,EAAE,IAAI,EAAE,qBAAqB,EAAE,OAAO,EAAE,qBAAqB,EAAE;IACrE,IAAI,EAAE,EAAE,IAAI,EAAE,4BAA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,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAEjE,wEAAwE;IACxE,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACnD,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,SAAS,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC5C,MAAM,MAAM,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;QAC3C,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IAED,OAAO,IAAI,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { loadConfig, saveConfig, getWallet, getApiUrl, getApiKey, clearApiKey, CONFIG_DIR } from './config.js';
|
|
2
|
+
export type { SilkConfig, WalletEntry } from './config.js';
|
|
3
|
+
export { loadContacts, saveContacts, addContact, removeContact, getContact, listContacts, resolveRecipient, initContacts } from './contacts.js';
|
|
4
|
+
export type { Contact, ContactsStore } from './contacts.js';
|
|
5
|
+
export { createHttpClient } from './client.js';
|
|
6
|
+
export type { ClientConfig } from './client.js';
|
|
7
|
+
export { getTransfer } from './transfers.js';
|
|
8
|
+
export type { TransferInfo, TokenInfo, PoolInfo } from './transfers.js';
|
|
9
|
+
export { SdkError, ANCHOR_ERROR_MAP, toSdkError } from './errors.js';
|
|
10
|
+
export { outputSuccess, outputError, wrapCommand } from './output.js';
|
|
11
|
+
export { validateAddress, validateAmount, fetchTransfer, validateClaim, validateCancel, validatePay } from './validate.js';
|
|
12
|
+
export { analyzeTransaction, verifyIntent } from './verify/index.js';
|
|
13
|
+
export type { TransactionAnalysis, InstructionAnalysis, RiskFlag, VerifyResult, Intent, AnalyzeOptions } from './verify/index.js';
|
|
14
|
+
export { verifyIntent as verifyIntentV2 } from './intent/index.js';
|
|
15
|
+
export type { Intent as IntentV2, SingleIntent, CompoundIntent, ActionIntent, Constraint, TokenRef, ProgramRef, ExecutionRef, Confidence, TransferIntent, SwapIntent, StakeIntent, LendIntent, BorrowIntent, ApproveIntent, WithdrawIntent, CustomIntent, VerifyResult as VerifyResultV2, ProgramInfo, } from './intent/index.js';
|
|
16
|
+
export { evaluateConstraint, createTokenRegistry, createProgramRegistry, getProgramRef, getExecutionRef, parseChain, normalizeAddress, isEvmChain } from './intent/index.js';
|
|
17
|
+
export { loadOrders, saveOrders, addOrder, getOrder, updateOrder, evaluateOrders, parseSwapSugar, } from './orders/index.js';
|
|
18
|
+
export type { Order, OrderStatus, ExecutionPolicy, OrderEvent, EvaluationResult, PriceFeed, OrdersStore, EvaluateOptions, ServerEvaluateResponse, SwapSugarInput, } from './orders/index.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { loadConfig, saveConfig, getWallet, getApiUrl, getApiKey, clearApiKey, CONFIG_DIR } from './config.js';
|
|
2
|
+
export { loadContacts, saveContacts, addContact, removeContact, getContact, listContacts, resolveRecipient, initContacts } from './contacts.js';
|
|
3
|
+
export { createHttpClient } from './client.js';
|
|
4
|
+
export { getTransfer } from './transfers.js';
|
|
5
|
+
export { SdkError, ANCHOR_ERROR_MAP, toSdkError } from './errors.js';
|
|
6
|
+
export { outputSuccess, outputError, wrapCommand } from './output.js';
|
|
7
|
+
export { validateAddress, validateAmount, fetchTransfer, validateClaim, validateCancel, validatePay } from './validate.js';
|
|
8
|
+
export { analyzeTransaction, verifyIntent } from './verify/index.js';
|
|
9
|
+
// Cross-chain intent framework
|
|
10
|
+
export { verifyIntent as verifyIntentV2 } from './intent/index.js';
|
|
11
|
+
export { evaluateConstraint, createTokenRegistry, createProgramRegistry, getProgramRef, getExecutionRef, parseChain, normalizeAddress, isEvmChain } from './intent/index.js';
|
|
12
|
+
// Standing orders
|
|
13
|
+
export { loadOrders, saveOrders, addOrder, getOrder, updateOrder, evaluateOrders, parseSwapSugar, } from './orders/index.js';
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE/G,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAEhJ,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC3H,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGrE,+BAA+B;AAC/B,OAAO,EAAE,YAAY,IAAI,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAsBnE,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,aAAa,EAAE,eAAe,EAAE,UAAU,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE7K,kBAAkB;AAClB,OAAO,EACL,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EACvD,cAAc,EACd,cAAc,GACf,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface ParsedChain {
|
|
2
|
+
chain: string;
|
|
3
|
+
network: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function parseChain(chainStr: string): ParsedChain;
|
|
6
|
+
export declare function isEvmChain(chain: string): boolean;
|
|
7
|
+
export declare function normalizeAddress(address: string, chain: string): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const EVM_CHAINS = new Set([
|
|
2
|
+
'ethereum', 'base', 'polygon', 'arbitrum', 'optimism', 'avalanche', 'bsc', 'gnosis', 'zksync', 'scroll', 'linea', 'mantle',
|
|
3
|
+
]);
|
|
4
|
+
export function parseChain(chainStr) {
|
|
5
|
+
const lower = chainStr.toLowerCase();
|
|
6
|
+
const colonIndex = lower.indexOf(':');
|
|
7
|
+
if (colonIndex === -1) {
|
|
8
|
+
return { chain: lower, network: 'mainnet' };
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
chain: lower.slice(0, colonIndex),
|
|
12
|
+
network: lower.slice(colonIndex + 1),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function isEvmChain(chain) {
|
|
16
|
+
return EVM_CHAINS.has(chain.toLowerCase());
|
|
17
|
+
}
|
|
18
|
+
export function normalizeAddress(address, chain) {
|
|
19
|
+
if (isEvmChain(chain)) {
|
|
20
|
+
return address.toLowerCase();
|
|
21
|
+
}
|
|
22
|
+
return address;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=chains.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chains.js","sourceRoot":"","sources":["../../src/intent/chains.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACzB,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ;CAC3H,CAAC,CAAC;AAOH,MAAM,UAAU,UAAU,CAAC,QAAgB;IACzC,MAAM,KAAK,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IACrC,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACtC,IAAI,UAAU,KAAK,CAAC,CAAC,EAAE,CAAC;QACtB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;IAC9C,CAAC;IACD,OAAO;QACL,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC;QACjC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC;KACrC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,OAAe,EAAE,KAAa;IAC7D,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,OAAO,CAAC,WAAW,EAAE,CAAC;IAC/B,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Constraint } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Evaluate whether an actual value satisfies a constraint.
|
|
4
|
+
*
|
|
5
|
+
* - Plain value: exact match within tolerance (for numbers).
|
|
6
|
+
* - Object with gte/lte/gt/lt: each specified bound is checked.
|
|
7
|
+
*/
|
|
8
|
+
export declare function evaluateConstraint(constraint: Constraint<number | string>, actual: number | string, tolerance?: number): boolean;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { compareDecimals, parseDecimal, withinRelativeTolerance } from '../amount-utils.js';
|
|
2
|
+
const DEFAULT_TOLERANCE = 0.0001; // 0.01%
|
|
3
|
+
/**
|
|
4
|
+
* Evaluate whether an actual value satisfies a constraint.
|
|
5
|
+
*
|
|
6
|
+
* - Plain value: exact match within tolerance (for numbers).
|
|
7
|
+
* - Object with gte/lte/gt/lt: each specified bound is checked.
|
|
8
|
+
*/
|
|
9
|
+
export function evaluateConstraint(constraint, actual, tolerance = DEFAULT_TOLERANCE) {
|
|
10
|
+
const actualDecimal = parseDecimal(actual);
|
|
11
|
+
const toleranceDecimal = parseDecimal(tolerance);
|
|
12
|
+
if (!actualDecimal || !toleranceDecimal) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
if (typeof constraint === 'number' || typeof constraint === 'string') {
|
|
16
|
+
const expectedDecimal = parseDecimal(constraint);
|
|
17
|
+
if (!expectedDecimal)
|
|
18
|
+
return false;
|
|
19
|
+
return withinRelativeTolerance(expectedDecimal, actualDecimal, toleranceDecimal);
|
|
20
|
+
}
|
|
21
|
+
if (constraint.gte !== undefined) {
|
|
22
|
+
const minInclusive = parseDecimal(constraint.gte);
|
|
23
|
+
if (!minInclusive || compareDecimals(actualDecimal, minInclusive) < 0)
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (constraint.lte !== undefined) {
|
|
27
|
+
const maxInclusive = parseDecimal(constraint.lte);
|
|
28
|
+
if (!maxInclusive || compareDecimals(actualDecimal, maxInclusive) > 0)
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
if (constraint.gt !== undefined) {
|
|
32
|
+
const minExclusive = parseDecimal(constraint.gt);
|
|
33
|
+
if (!minExclusive || compareDecimals(actualDecimal, minExclusive) <= 0)
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
if (constraint.lt !== undefined) {
|
|
37
|
+
const maxExclusive = parseDecimal(constraint.lt);
|
|
38
|
+
if (!maxExclusive || compareDecimals(actualDecimal, maxExclusive) >= 0)
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=constraints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constraints.js","sourceRoot":"","sources":["../../src/intent/constraints.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAE5F,MAAM,iBAAiB,GAAG,MAAM,CAAC,CAAC,QAAQ;AAE1C;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAChC,UAAuC,EACvC,MAAuB,EACvB,YAAoB,iBAAiB;IAErC,MAAM,aAAa,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IAC3C,MAAM,gBAAgB,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;IACjD,IAAI,CAAC,aAAa,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACrE,MAAM,eAAe,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;QACjD,IAAI,CAAC,eAAe;YAAE,OAAO,KAAK,CAAC;QACnC,OAAO,uBAAuB,CAAC,eAAe,EAAE,aAAa,EAAE,gBAAgB,CAAC,CAAC;IACnF,CAAC;IAED,IAAI,UAAU,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;QACjC,MAAM,YAAY,GAAG,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAClD,IAAI,CAAC,YAAY,IAAI,eAAe,CAAC,aAAa,EAAE,YAAY,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;IACtF,CAAC;IACD,IAAI,UAAU,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;QACjC,MAAM,YAAY,GAAG,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAClD,IAAI,CAAC,YAAY,IAAI,eAAe,CAAC,aAAa,EAAE,YAAY,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;IACtF,CAAC;IACD,IAAI,UAAU,CAAC,EAAE,KAAK,SAAS,EAAE,CAAC;QAChC,MAAM,YAAY,GAAG,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QACjD,IAAI,CAAC,YAAY,IAAI,eAAe,CAAC,aAAa,EAAE,YAAY,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;IACvF,CAAC;IACD,IAAI,UAAU,CAAC,EAAE,KAAK,SAAS,EAAE,CAAC;QAChC,MAAM,YAAY,GAAG,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QACjD,IAAI,CAAC,YAAY,IAAI,eAAe,CAAC,aAAa,EAAE,YAAY,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;IACvF,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Intent, SingleIntent, CompoundIntent, ActionIntent, ProgramRef, ExecutionRef } from './types.js';
|
|
2
|
+
export declare function isSingleIntent(intent: Intent): intent is SingleIntent;
|
|
3
|
+
export declare function isCompoundIntent(intent: Intent): intent is CompoundIntent;
|
|
4
|
+
export declare function getActions(intent: Intent): ActionIntent[];
|
|
5
|
+
export declare function getProgramRef(intent: Intent): ProgramRef;
|
|
6
|
+
export declare function getExecutionRef(intent: Intent): ExecutionRef;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function isSingleIntent(intent) {
|
|
2
|
+
return 'action' in intent;
|
|
3
|
+
}
|
|
4
|
+
export function isCompoundIntent(intent) {
|
|
5
|
+
return 'actions' in intent;
|
|
6
|
+
}
|
|
7
|
+
export function getActions(intent) {
|
|
8
|
+
if (isCompoundIntent(intent)) {
|
|
9
|
+
return intent.actions;
|
|
10
|
+
}
|
|
11
|
+
// Extract just the action fields (without chain/strict/program/programName/signer/feePayer)
|
|
12
|
+
const { chain: _chain, strict: _strict, program: _program, programName: _programName, signer: _signer, feePayer: _feePayer, ...action } = intent;
|
|
13
|
+
return [action];
|
|
14
|
+
}
|
|
15
|
+
export function getProgramRef(intent) {
|
|
16
|
+
return {
|
|
17
|
+
programName: intent.programName,
|
|
18
|
+
program: intent.program,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function getExecutionRef(intent) {
|
|
22
|
+
return {
|
|
23
|
+
signer: intent.signer,
|
|
24
|
+
feePayer: intent.feePayer,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/intent/helpers.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,OAAO,QAAQ,IAAI,MAAM,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,OAAO,SAAS,IAAI,MAAM,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAc;IACvC,IAAI,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,OAAO,MAAM,CAAC,OAAO,CAAC;IACxB,CAAC;IACD,4FAA4F;IAC5F,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,GAAG,MAAsB,CAAC;IACjK,OAAO,CAAC,MAAsB,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,MAAc;IAC1C,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,OAAO,EAAE,MAAM,CAAC,OAAO;KACxB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;KAC1B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Intent, VerifyResult } from './types.js';
|
|
2
|
+
import type { AnalyzeOptions } from '../verify/index.js';
|
|
3
|
+
export type { Intent, SingleIntent, CompoundIntent, ActionIntent, Constraint, TokenRef, ProgramRef, ExecutionRef, VerifyResult, Confidence } from './types.js';
|
|
4
|
+
export type { TransferIntent, SwapIntent, StakeIntent, LendIntent, BorrowIntent, ApproveIntent, WithdrawIntent, CustomIntent } from './types.js';
|
|
5
|
+
export type { ProgramInfo } from './program-registry.js';
|
|
6
|
+
export { evaluateConstraint } from './constraints.js';
|
|
7
|
+
export { createTokenRegistry } from './token-registry.js';
|
|
8
|
+
export { createProgramRegistry } from './program-registry.js';
|
|
9
|
+
export { getProgramRef, getExecutionRef } from './helpers.js';
|
|
10
|
+
export { parseChain, normalizeAddress, isEvmChain } from './chains.js';
|
|
11
|
+
export declare function verifyIntent(txBytes: string, intent: Intent, opts?: AnalyzeOptions): Promise<VerifyResult>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { analyzeTransaction as solanaAnalyze } from '../verify/index.js';
|
|
2
|
+
import { parseChain } from './chains.js';
|
|
3
|
+
import { getActions, getProgramRef } from './helpers.js';
|
|
4
|
+
import { matchIntent } from './matcher.js';
|
|
5
|
+
import { createProgramRegistry } from './program-registry.js';
|
|
6
|
+
export { evaluateConstraint } from './constraints.js';
|
|
7
|
+
export { createTokenRegistry } from './token-registry.js';
|
|
8
|
+
export { createProgramRegistry } from './program-registry.js';
|
|
9
|
+
export { getProgramRef, getExecutionRef } from './helpers.js';
|
|
10
|
+
export { parseChain, normalizeAddress, isEvmChain } from './chains.js';
|
|
11
|
+
// Maps generic action names to adapter-specific decoded instruction types.
|
|
12
|
+
const SOLANA_ACTION_MAP = {
|
|
13
|
+
transfer: 'create_transfer',
|
|
14
|
+
};
|
|
15
|
+
const programRegistry = createProgramRegistry();
|
|
16
|
+
export async function verifyIntent(txBytes, intent, opts = {}) {
|
|
17
|
+
if (!intent.chain) {
|
|
18
|
+
return {
|
|
19
|
+
matched: false,
|
|
20
|
+
confidence: 'unverified',
|
|
21
|
+
discrepancies: ['Intent is missing required "chain" field.'],
|
|
22
|
+
analysis: { feePayer: '', instructions: [], flags: [], summary: '' },
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const { chain, network } = parseChain(intent.chain);
|
|
26
|
+
const strict = intent.strict ?? false;
|
|
27
|
+
const actions = getActions(intent);
|
|
28
|
+
// Resolve expected program from ProgramRef
|
|
29
|
+
const programRef = getProgramRef(intent);
|
|
30
|
+
let expectedProgram;
|
|
31
|
+
if (programRef.program && programRef.programName) {
|
|
32
|
+
// Both specified: cross-check
|
|
33
|
+
if (!programRegistry.crossCheck(chain, network, programRef.programName, programRef.program)) {
|
|
34
|
+
return {
|
|
35
|
+
matched: false,
|
|
36
|
+
confidence: 'full',
|
|
37
|
+
discrepancies: [
|
|
38
|
+
`Program cross-check failed: name '${programRef.programName}' does not match address '${programRef.program}'.`,
|
|
39
|
+
],
|
|
40
|
+
analysis: { feePayer: '', instructions: [], flags: [], summary: '' },
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
expectedProgram = programRef.program;
|
|
44
|
+
}
|
|
45
|
+
else if (programRef.program) {
|
|
46
|
+
expectedProgram = programRef.program;
|
|
47
|
+
}
|
|
48
|
+
else if (programRef.programName) {
|
|
49
|
+
const resolved = programRegistry.resolveName(chain, network, programRef.programName);
|
|
50
|
+
if (resolved) {
|
|
51
|
+
expectedProgram = resolved.address;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
let analysis;
|
|
55
|
+
if (chain === 'solana') {
|
|
56
|
+
analysis = await solanaAnalyze(txBytes, opts);
|
|
57
|
+
for (const ix of analysis.instructions) {
|
|
58
|
+
for (const [generic, specific] of Object.entries(SOLANA_ACTION_MAP)) {
|
|
59
|
+
if (ix.type === specific) {
|
|
60
|
+
ix.type = generic;
|
|
61
|
+
if (ix.params['sender']) {
|
|
62
|
+
ix.params['from'] = ix.params['sender'];
|
|
63
|
+
}
|
|
64
|
+
if (ix.params['recipient']) {
|
|
65
|
+
ix.params['to'] = ix.params['recipient'];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
return {
|
|
73
|
+
matched: false,
|
|
74
|
+
confidence: 'unverified',
|
|
75
|
+
discrepancies: [`Chain adapter for '${chain}' is not yet implemented.`],
|
|
76
|
+
analysis: { feePayer: '', instructions: [], flags: [], summary: '' },
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const result = matchIntent(actions, analysis.instructions, analysis.flags, chain, strict, expectedProgram);
|
|
80
|
+
return {
|
|
81
|
+
matched: result.matched,
|
|
82
|
+
confidence: result.confidence,
|
|
83
|
+
discrepancies: result.discrepancies,
|
|
84
|
+
analysis,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/intent/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAK9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,M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,CAAC;oBAC1C,CAAC;oBACD,IAAI,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;wBAC3B,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;oBAC3C,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO;YACL,OAAO,EAAE,KAAK;YACd,UAAU,EAAE,YAAY;YACxB,aAAa,EAAE,CAAC,sBAAsB,KAAK,2BAA2B,CAAC;YACvE,QAAQ,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;SACrE,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC;IAE3G,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,QAAQ;KACT,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ActionIntent, Confidence } from './types.js';
|
|
2
|
+
import type { InstructionAnalysis, RiskFlag } from '../verify/index.js';
|
|
3
|
+
export interface MatchResult {
|
|
4
|
+
matched: boolean;
|
|
5
|
+
confidence: Confidence;
|
|
6
|
+
discrepancies: string[];
|
|
7
|
+
}
|
|
8
|
+
export declare function matchIntent(actions: ActionIntent[], instructions: InstructionAnalysis[], globalFlags: RiskFlag[], chain: string, strict: boolean, expectedProgram?: string): MatchResult;
|