@haneullabs/wallet-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/CHANGELOG.md +69 -0
- package/README.md +1 -0
- package/dist/cjs/auto-approvals/analyzer.d.ts +71 -0
- package/dist/cjs/auto-approvals/analyzer.js +70 -0
- package/dist/cjs/auto-approvals/analyzer.js.map +7 -0
- package/dist/cjs/auto-approvals/index.d.ts +6 -0
- package/dist/cjs/auto-approvals/index.js +33 -0
- package/dist/cjs/auto-approvals/index.js.map +7 -0
- package/dist/cjs/auto-approvals/intent.d.ts +5 -0
- package/dist/cjs/auto-approvals/intent.js +65 -0
- package/dist/cjs/auto-approvals/intent.js.map +7 -0
- package/dist/cjs/auto-approvals/manager.d.ts +31 -0
- package/dist/cjs/auto-approvals/manager.js +328 -0
- package/dist/cjs/auto-approvals/manager.js.map +7 -0
- package/dist/cjs/auto-approvals/schemas/index.d.ts +4 -0
- package/dist/cjs/auto-approvals/schemas/index.js +28 -0
- package/dist/cjs/auto-approvals/schemas/index.js.map +7 -0
- package/dist/cjs/auto-approvals/schemas/policy.d.ts +145 -0
- package/dist/cjs/auto-approvals/schemas/policy.js +79 -0
- package/dist/cjs/auto-approvals/schemas/policy.js.map +7 -0
- package/dist/cjs/auto-approvals/schemas/state.d.ts +115 -0
- package/dist/cjs/auto-approvals/schemas/state.js +49 -0
- package/dist/cjs/auto-approvals/schemas/state.js.map +7 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +20 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/package.json +5 -0
- package/dist/cjs/transaction-analyzer/analyzer.d.ts +34 -0
- package/dist/cjs/transaction-analyzer/analyzer.js +94 -0
- package/dist/cjs/transaction-analyzer/analyzer.js.map +7 -0
- package/dist/cjs/transaction-analyzer/index.d.ts +9 -0
- package/dist/cjs/transaction-analyzer/index.js +28 -0
- package/dist/cjs/transaction-analyzer/index.js.map +7 -0
- package/dist/cjs/transaction-analyzer/rules/accessLevel.d.ts +29 -0
- package/dist/cjs/transaction-analyzer/rules/accessLevel.js +106 -0
- package/dist/cjs/transaction-analyzer/rules/accessLevel.js.map +7 -0
- package/dist/cjs/transaction-analyzer/rules/coin-flows.d.ts +313 -0
- package/dist/cjs/transaction-analyzer/rules/coin-flows.js +179 -0
- package/dist/cjs/transaction-analyzer/rules/coin-flows.js.map +7 -0
- package/dist/cjs/transaction-analyzer/rules/coin-value.d.ts +42 -0
- package/dist/cjs/transaction-analyzer/rules/coin-value.js +60 -0
- package/dist/cjs/transaction-analyzer/rules/coin-value.js.map +7 -0
- package/dist/cjs/transaction-analyzer/rules/coins.d.ts +337 -0
- package/dist/cjs/transaction-analyzer/rules/coins.js +78 -0
- package/dist/cjs/transaction-analyzer/rules/coins.js.map +7 -0
- package/dist/cjs/transaction-analyzer/rules/commands.d.ts +366 -0
- package/dist/cjs/transaction-analyzer/rules/commands.js +148 -0
- package/dist/cjs/transaction-analyzer/rules/commands.js.map +7 -0
- package/dist/cjs/transaction-analyzer/rules/core.d.ts +314 -0
- package/dist/cjs/transaction-analyzer/rules/core.js +73 -0
- package/dist/cjs/transaction-analyzer/rules/core.js.map +7 -0
- package/dist/cjs/transaction-analyzer/rules/functions.d.ts +292 -0
- package/dist/cjs/transaction-analyzer/rules/functions.js +58 -0
- package/dist/cjs/transaction-analyzer/rules/functions.js.map +7 -0
- package/dist/cjs/transaction-analyzer/rules/index.d.ts +2244 -0
- package/dist/cjs/transaction-analyzer/rules/index.js +52 -0
- package/dist/cjs/transaction-analyzer/rules/index.js.map +7 -0
- package/dist/cjs/transaction-analyzer/rules/inputs.d.ts +313 -0
- package/dist/cjs/transaction-analyzer/rules/inputs.js +49 -0
- package/dist/cjs/transaction-analyzer/rules/inputs.js.map +7 -0
- package/dist/cjs/transaction-analyzer/rules/objects.d.ts +359 -0
- package/dist/cjs/transaction-analyzer/rules/objects.js +124 -0
- package/dist/cjs/transaction-analyzer/rules/objects.js.map +7 -0
- package/dist/cjs/util.d.ts +5 -0
- package/dist/cjs/util.js +17 -0
- package/dist/cjs/util.js.map +7 -0
- package/dist/esm/auto-approvals/analyzer.d.ts +71 -0
- package/dist/esm/auto-approvals/analyzer.js +50 -0
- package/dist/esm/auto-approvals/analyzer.js.map +7 -0
- package/dist/esm/auto-approvals/index.d.ts +6 -0
- package/dist/esm/auto-approvals/index.js +12 -0
- package/dist/esm/auto-approvals/index.js.map +7 -0
- package/dist/esm/auto-approvals/intent.d.ts +5 -0
- package/dist/esm/auto-approvals/intent.js +45 -0
- package/dist/esm/auto-approvals/intent.js.map +7 -0
- package/dist/esm/auto-approvals/manager.d.ts +31 -0
- package/dist/esm/auto-approvals/manager.js +308 -0
- package/dist/esm/auto-approvals/manager.js.map +7 -0
- package/dist/esm/auto-approvals/schemas/index.d.ts +4 -0
- package/dist/esm/auto-approvals/schemas/index.js +8 -0
- package/dist/esm/auto-approvals/schemas/index.js.map +7 -0
- package/dist/esm/auto-approvals/schemas/policy.d.ts +145 -0
- package/dist/esm/auto-approvals/schemas/policy.js +49 -0
- package/dist/esm/auto-approvals/schemas/policy.js.map +7 -0
- package/dist/esm/auto-approvals/schemas/state.d.ts +115 -0
- package/dist/esm/auto-approvals/schemas/state.js +19 -0
- package/dist/esm/auto-approvals/schemas/state.js.map +7 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/package.json +5 -0
- package/dist/esm/transaction-analyzer/analyzer.d.ts +34 -0
- package/dist/esm/transaction-analyzer/analyzer.js +74 -0
- package/dist/esm/transaction-analyzer/analyzer.js.map +7 -0
- package/dist/esm/transaction-analyzer/index.d.ts +9 -0
- package/dist/esm/transaction-analyzer/index.js +8 -0
- package/dist/esm/transaction-analyzer/index.js.map +7 -0
- package/dist/esm/transaction-analyzer/rules/accessLevel.d.ts +29 -0
- package/dist/esm/transaction-analyzer/rules/accessLevel.js +86 -0
- package/dist/esm/transaction-analyzer/rules/accessLevel.js.map +7 -0
- package/dist/esm/transaction-analyzer/rules/coin-flows.d.ts +313 -0
- package/dist/esm/transaction-analyzer/rules/coin-flows.js +159 -0
- package/dist/esm/transaction-analyzer/rules/coin-flows.js.map +7 -0
- package/dist/esm/transaction-analyzer/rules/coin-value.d.ts +42 -0
- package/dist/esm/transaction-analyzer/rules/coin-value.js +40 -0
- package/dist/esm/transaction-analyzer/rules/coin-value.js.map +7 -0
- package/dist/esm/transaction-analyzer/rules/coins.d.ts +337 -0
- package/dist/esm/transaction-analyzer/rules/coins.js +58 -0
- package/dist/esm/transaction-analyzer/rules/coins.js.map +7 -0
- package/dist/esm/transaction-analyzer/rules/commands.d.ts +366 -0
- package/dist/esm/transaction-analyzer/rules/commands.js +128 -0
- package/dist/esm/transaction-analyzer/rules/commands.js.map +7 -0
- package/dist/esm/transaction-analyzer/rules/core.d.ts +314 -0
- package/dist/esm/transaction-analyzer/rules/core.js +53 -0
- package/dist/esm/transaction-analyzer/rules/core.js.map +7 -0
- package/dist/esm/transaction-analyzer/rules/functions.d.ts +292 -0
- package/dist/esm/transaction-analyzer/rules/functions.js +38 -0
- package/dist/esm/transaction-analyzer/rules/functions.js.map +7 -0
- package/dist/esm/transaction-analyzer/rules/index.d.ts +2244 -0
- package/dist/esm/transaction-analyzer/rules/index.js +32 -0
- package/dist/esm/transaction-analyzer/rules/index.js.map +7 -0
- package/dist/esm/transaction-analyzer/rules/inputs.d.ts +313 -0
- package/dist/esm/transaction-analyzer/rules/inputs.js +29 -0
- package/dist/esm/transaction-analyzer/rules/inputs.js.map +7 -0
- package/dist/esm/transaction-analyzer/rules/objects.d.ts +359 -0
- package/dist/esm/transaction-analyzer/rules/objects.js +104 -0
- package/dist/esm/transaction-analyzer/rules/objects.js.map +7 -0
- package/dist/esm/util.d.ts +5 -0
- package/dist/esm/util.js +1 -0
- package/dist/esm/util.js.map +7 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { operationType, extractOperationType, OPERATION_INTENT } from "./intent.js";
|
|
2
|
+
import { autoApprovalAnalyzer } from "./analyzer.js";
|
|
3
|
+
import { AutoApprovalManager } from "./manager.js";
|
|
4
|
+
export * from "./schemas/index.js";
|
|
5
|
+
export {
|
|
6
|
+
AutoApprovalManager,
|
|
7
|
+
OPERATION_INTENT,
|
|
8
|
+
autoApprovalAnalyzer,
|
|
9
|
+
extractOperationType,
|
|
10
|
+
operationType
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/auto-approvals/index.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport { operationType, extractOperationType, OPERATION_INTENT } from './intent.js';\nexport { autoApprovalAnalyzer } from './analyzer.js';\nexport type { AutoApprovalResult, AutoApprovalAnalysis } from './analyzer.js';\n\nexport { AutoApprovalManager } from './manager.js';\nexport type { AutoApprovalIssue, AutoApprovalCheck } from './manager.js';\n\nexport * from './schemas/index.js';\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,eAAe,sBAAsB,wBAAwB;AACtE,SAAS,4BAA4B;AAGrC,SAAS,2BAA2B;AAGpC,cAAc;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Transaction, TransactionResult } from '@haneullabs/haneul/transactions';
|
|
2
|
+
import type { TransactionDataBuilder } from '@haneullabs/haneul/transactions';
|
|
3
|
+
export declare const OPERATION_INTENT = "@haneullabs/wallet-kit/AutoApprovalOperation";
|
|
4
|
+
export declare function operationType(operationType: string): (tx: Transaction) => TransactionResult;
|
|
5
|
+
export declare function extractOperationType(cb: (operationType: string) => void): (transactionData: TransactionDataBuilder, _options: unknown, next: () => Promise<void>) => Promise<void>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Commands } from "@haneullabs/haneul/transactions";
|
|
2
|
+
const OPERATION_INTENT = "@haneullabs/wallet-kit/AutoApprovalOperation";
|
|
3
|
+
function operationType(operationType2) {
|
|
4
|
+
return (tx) => {
|
|
5
|
+
tx.addIntentResolver(OPERATION_INTENT, (transactionData, _options, next) => {
|
|
6
|
+
replaceOperationTypeIntent(transactionData);
|
|
7
|
+
return next();
|
|
8
|
+
});
|
|
9
|
+
const result = tx.add(
|
|
10
|
+
Commands.Intent({
|
|
11
|
+
name: OPERATION_INTENT,
|
|
12
|
+
inputs: {},
|
|
13
|
+
data: { operationType: operationType2 }
|
|
14
|
+
})
|
|
15
|
+
);
|
|
16
|
+
return result;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function extractOperationType(cb) {
|
|
20
|
+
return (transactionData, _options, next) => {
|
|
21
|
+
replaceOperationTypeIntent(transactionData, cb);
|
|
22
|
+
return next();
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function replaceOperationTypeIntent(transactionData, cb) {
|
|
26
|
+
let intentFound = false;
|
|
27
|
+
for (let index = 0; index < transactionData.commands.length; index++) {
|
|
28
|
+
const command = transactionData.commands[index];
|
|
29
|
+
if (command.$kind === "$Intent" && command.$Intent.name === OPERATION_INTENT) {
|
|
30
|
+
if (intentFound) {
|
|
31
|
+
throw new Error("Multiple operation type intents found in transaction");
|
|
32
|
+
}
|
|
33
|
+
intentFound = true;
|
|
34
|
+
const operationType2 = command.$Intent.data.operationType;
|
|
35
|
+
transactionData.replaceCommand(index, []);
|
|
36
|
+
cb?.(operationType2);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
OPERATION_INTENT,
|
|
42
|
+
extractOperationType,
|
|
43
|
+
operationType
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=intent.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/auto-approvals/intent.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Transaction, TransactionResult } from '@haneullabs/haneul/transactions';\nimport type { TransactionDataBuilder } from '@haneullabs/haneul/transactions';\nimport { Commands } from '@haneullabs/haneul/transactions';\n\nexport const OPERATION_INTENT = '@haneullabs/wallet-kit/AutoApprovalOperation';\n\nexport function operationType(operationType: string) {\n\treturn (tx: Transaction): TransactionResult => {\n\t\ttx.addIntentResolver(OPERATION_INTENT, (transactionData, _options, next) => {\n\t\t\treplaceOperationTypeIntent(transactionData);\n\t\t\treturn next();\n\t\t});\n\n\t\tconst result = tx.add(\n\t\t\tCommands.Intent({\n\t\t\t\tname: OPERATION_INTENT,\n\t\t\t\tinputs: {},\n\t\t\t\tdata: { operationType },\n\t\t\t}),\n\t\t);\n\n\t\treturn result;\n\t};\n}\n\nexport function extractOperationType(cb: (operationType: string) => void) {\n\treturn (\n\t\ttransactionData: TransactionDataBuilder,\n\t\t_options: unknown,\n\t\tnext: () => Promise<void>,\n\t) => {\n\t\treplaceOperationTypeIntent(transactionData, cb);\n\t\treturn next();\n\t};\n}\n\nfunction replaceOperationTypeIntent(\n\ttransactionData: TransactionDataBuilder,\n\tcb?: (operationType: string) => void,\n) {\n\tlet intentFound = false;\n\tfor (let index = 0; index < transactionData.commands.length; index++) {\n\t\tconst command = transactionData.commands[index];\n\t\tif (command.$kind === '$Intent' && command.$Intent.name === OPERATION_INTENT) {\n\t\t\tif (intentFound) {\n\t\t\t\tthrow new Error('Multiple operation type intents found in transaction');\n\t\t\t}\n\t\t\tintentFound = true;\n\t\t\tconst operationType = command.$Intent.data.operationType as string;\n\t\t\ttransactionData.replaceCommand(index, []);\n\t\t\tcb?.(operationType);\n\t\t}\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAKA,SAAS,gBAAgB;AAElB,MAAM,mBAAmB;AAEzB,SAAS,cAAcA,gBAAuB;AACpD,SAAO,CAAC,OAAuC;AAC9C,OAAG,kBAAkB,kBAAkB,CAAC,iBAAiB,UAAU,SAAS;AAC3E,iCAA2B,eAAe;AAC1C,aAAO,KAAK;AAAA,IACb,CAAC;AAED,UAAM,SAAS,GAAG;AAAA,MACjB,SAAS,OAAO;AAAA,QACf,MAAM;AAAA,QACN,QAAQ,CAAC;AAAA,QACT,MAAM,EAAE,eAAAA,eAAc;AAAA,MACvB,CAAC;AAAA,IACF;AAEA,WAAO;AAAA,EACR;AACD;AAEO,SAAS,qBAAqB,IAAqC;AACzE,SAAO,CACN,iBACA,UACA,SACI;AACJ,+BAA2B,iBAAiB,EAAE;AAC9C,WAAO,KAAK;AAAA,EACb;AACD;AAEA,SAAS,2BACR,iBACA,IACC;AACD,MAAI,cAAc;AAClB,WAAS,QAAQ,GAAG,QAAQ,gBAAgB,SAAS,QAAQ,SAAS;AACrE,UAAM,UAAU,gBAAgB,SAAS,KAAK;AAC9C,QAAI,QAAQ,UAAU,aAAa,QAAQ,QAAQ,SAAS,kBAAkB;AAC7E,UAAI,aAAa;AAChB,cAAM,IAAI,MAAM,sDAAsD;AAAA,MACvE;AACA,oBAAc;AACd,YAAMA,iBAAgB,QAAQ,QAAQ,KAAK;AAC3C,sBAAgB,eAAe,OAAO,CAAC,CAAC;AACxC,WAAKA,cAAa;AAAA,IACnB;AAAA,EACD;AACD;",
|
|
6
|
+
"names": ["operationType"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Experimental_HaneulClientTypes } from '@haneullabs/haneul/experimental';
|
|
2
|
+
import type { AutoApprovalState } from './schemas/state.js';
|
|
3
|
+
import type { AutoApprovalSettings } from './schemas/policy.js';
|
|
4
|
+
import type { AutoApprovalResult } from './analyzer.js';
|
|
5
|
+
export interface AutoApprovalManagerOptions {
|
|
6
|
+
policy: string;
|
|
7
|
+
state: string | null;
|
|
8
|
+
}
|
|
9
|
+
export interface AutoApprovalIssue {
|
|
10
|
+
message: string;
|
|
11
|
+
}
|
|
12
|
+
export interface AutoApprovalCheck {
|
|
13
|
+
matchesPolicy: boolean;
|
|
14
|
+
canAutoApprove: boolean;
|
|
15
|
+
policyIssues: AutoApprovalIssue[];
|
|
16
|
+
settingsIssues: AutoApprovalIssue[];
|
|
17
|
+
analysisIssues: AutoApprovalIssue[];
|
|
18
|
+
}
|
|
19
|
+
export declare class AutoApprovalManager {
|
|
20
|
+
#private;
|
|
21
|
+
constructor(options: AutoApprovalManagerOptions);
|
|
22
|
+
checkTransaction(analysis: AutoApprovalResult): AutoApprovalCheck;
|
|
23
|
+
commitTransaction(analysis: AutoApprovalResult): void;
|
|
24
|
+
revertTransaction(analysis: AutoApprovalResult): void;
|
|
25
|
+
applyTransactionEffects(analysis: AutoApprovalResult, result: Experimental_HaneulClientTypes.TransactionResponse): void;
|
|
26
|
+
reset(): void;
|
|
27
|
+
export(): string;
|
|
28
|
+
getState(): AutoApprovalState;
|
|
29
|
+
getSettings(): AutoApprovalSettings | null;
|
|
30
|
+
updateSettings(settings: AutoApprovalSettings): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
9
|
+
var _state, _AutoApprovalManager_instances, matchesPolicy_fn, canAutoApprove_fn, revertCoinFlows_fn, removePendingDigest_fn;
|
|
10
|
+
import { parse, safeParse } from "valibot";
|
|
11
|
+
import { AutoApprovalStateSchema } from "./schemas/state.js";
|
|
12
|
+
import { AutoApprovalPolicySchema, AutoApprovalSettingsSchema } from "./schemas/policy.js";
|
|
13
|
+
import { parseStructTag } from "@haneullabs/haneul/utils";
|
|
14
|
+
class AutoApprovalManager {
|
|
15
|
+
constructor(options) {
|
|
16
|
+
__privateAdd(this, _AutoApprovalManager_instances);
|
|
17
|
+
__privateAdd(this, _state);
|
|
18
|
+
let state = null;
|
|
19
|
+
if (options.state) {
|
|
20
|
+
const parseResult = safeParse(AutoApprovalStateSchema, JSON.parse(options.state));
|
|
21
|
+
if (parseResult.success) {
|
|
22
|
+
const providedPolicy = parse(AutoApprovalPolicySchema, JSON.parse(options.policy));
|
|
23
|
+
const currentPolicy = parseResult.output.policy;
|
|
24
|
+
if (JSON.stringify(currentPolicy) === JSON.stringify(providedPolicy)) {
|
|
25
|
+
state = parseResult.output;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
__privateSet(this, _state, state ?? parse(AutoApprovalStateSchema, {
|
|
30
|
+
schemaVersion: "1.0.0",
|
|
31
|
+
policy: parse(AutoApprovalPolicySchema, JSON.parse(options.policy)),
|
|
32
|
+
settings: null,
|
|
33
|
+
pendingDigests: []
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
checkTransaction(analysis) {
|
|
37
|
+
const results = {
|
|
38
|
+
matchesPolicy: false,
|
|
39
|
+
canAutoApprove: false,
|
|
40
|
+
analysisIssues: [...analysis.issues ?? []],
|
|
41
|
+
policyIssues: [],
|
|
42
|
+
settingsIssues: []
|
|
43
|
+
};
|
|
44
|
+
if (results.analysisIssues.length > 0) {
|
|
45
|
+
return results;
|
|
46
|
+
}
|
|
47
|
+
const policyIssues = __privateMethod(this, _AutoApprovalManager_instances, matchesPolicy_fn).call(this, analysis);
|
|
48
|
+
if (policyIssues.length > 0) {
|
|
49
|
+
results.policyIssues = policyIssues;
|
|
50
|
+
return results;
|
|
51
|
+
} else {
|
|
52
|
+
results.matchesPolicy = true;
|
|
53
|
+
}
|
|
54
|
+
const settingsIssues = __privateMethod(this, _AutoApprovalManager_instances, canAutoApprove_fn).call(this, analysis);
|
|
55
|
+
if (settingsIssues.length > 0) {
|
|
56
|
+
results.settingsIssues = settingsIssues;
|
|
57
|
+
return results;
|
|
58
|
+
} else {
|
|
59
|
+
results.canAutoApprove = true;
|
|
60
|
+
}
|
|
61
|
+
return results;
|
|
62
|
+
}
|
|
63
|
+
// TODO: we should ensure that only 1 tx is pending at a time, and pending txs can't increase budgets
|
|
64
|
+
commitTransaction(analysis) {
|
|
65
|
+
if (!__privateGet(this, _state).settings) {
|
|
66
|
+
throw new Error("No auto-approval settings configured");
|
|
67
|
+
}
|
|
68
|
+
if (!analysis.result) {
|
|
69
|
+
throw new Error("Transaction analysis failed");
|
|
70
|
+
}
|
|
71
|
+
if (__privateGet(this, _state).settings.remainingTransactions !== null && __privateGet(this, _state).settings) {
|
|
72
|
+
__privateGet(this, _state).settings.remainingTransactions = Math.max(
|
|
73
|
+
0,
|
|
74
|
+
__privateGet(this, _state).settings.remainingTransactions - 1
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
for (const outflow of analysis.result.coinFlows.outflows) {
|
|
78
|
+
if (__privateGet(this, _state).settings.coinBudgets[outflow.coinType] !== void 0) {
|
|
79
|
+
const currentBudget = BigInt(__privateGet(this, _state).settings?.coinBudgets[outflow.coinType] ?? "0");
|
|
80
|
+
const newBalance = currentBudget - outflow.amount;
|
|
81
|
+
__privateGet(this, _state).settings.coinBudgets[outflow.coinType] = newBalance.toString();
|
|
82
|
+
} else {
|
|
83
|
+
if (__privateGet(this, _state).settings.sharedBudget === null) {
|
|
84
|
+
throw new Error("No budget available for coin type " + outflow.coinType);
|
|
85
|
+
}
|
|
86
|
+
const coinValue = analysis.result.coinValues.coinTypes.find(
|
|
87
|
+
(ct) => ct.coinType === outflow.coinType
|
|
88
|
+
);
|
|
89
|
+
if (!coinValue) {
|
|
90
|
+
throw new Error("No value available for coin type " + outflow.coinType);
|
|
91
|
+
}
|
|
92
|
+
__privateGet(this, _state).settings.sharedBudget -= coinValue.convertedAmount;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
__privateGet(this, _state).pendingDigests.push(analysis.result.digest);
|
|
96
|
+
}
|
|
97
|
+
revertTransaction(analysis) {
|
|
98
|
+
if (analysis.result?.digest) {
|
|
99
|
+
__privateMethod(this, _AutoApprovalManager_instances, removePendingDigest_fn).call(this, analysis.result?.digest);
|
|
100
|
+
}
|
|
101
|
+
if (__privateGet(this, _state).settings?.remainingTransactions !== null && __privateGet(this, _state).settings) {
|
|
102
|
+
__privateGet(this, _state).settings.remainingTransactions += 1;
|
|
103
|
+
}
|
|
104
|
+
__privateMethod(this, _AutoApprovalManager_instances, revertCoinFlows_fn).call(this, analysis);
|
|
105
|
+
}
|
|
106
|
+
applyTransactionEffects(analysis, result) {
|
|
107
|
+
__privateMethod(this, _AutoApprovalManager_instances, removePendingDigest_fn).call(this, result.digest);
|
|
108
|
+
if (!__privateGet(this, _state).settings) {
|
|
109
|
+
throw new Error("No auto-approval settings configured");
|
|
110
|
+
}
|
|
111
|
+
if (!analysis.result) {
|
|
112
|
+
throw new Error("Transaction analysis failed");
|
|
113
|
+
}
|
|
114
|
+
__privateMethod(this, _AutoApprovalManager_instances, revertCoinFlows_fn).call(this, analysis);
|
|
115
|
+
for (const change of result.balanceChanges) {
|
|
116
|
+
if (__privateGet(this, _state).settings.coinBudgets[change.coinType] !== void 0) {
|
|
117
|
+
const currentBudget = BigInt(__privateGet(this, _state).settings?.coinBudgets[change.coinType] ?? "0");
|
|
118
|
+
const newBalance = currentBudget + BigInt(change.amount);
|
|
119
|
+
if (__privateGet(this, _state).settings) {
|
|
120
|
+
__privateGet(this, _state).settings.coinBudgets[change.coinType] = newBalance.toString();
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
if (__privateGet(this, _state).settings.sharedBudget === null) {
|
|
124
|
+
throw new Error("No budget available for coin type " + change.coinType);
|
|
125
|
+
}
|
|
126
|
+
const coinValue = analysis.result.coinValues.coinTypes.find(
|
|
127
|
+
(ct) => ct.coinType === change.coinType
|
|
128
|
+
);
|
|
129
|
+
if (!coinValue) {
|
|
130
|
+
throw new Error("No value available for coin type " + change.coinType);
|
|
131
|
+
}
|
|
132
|
+
const convertedChange = Number(change.amount) / 10 ** coinValue.decimals * coinValue.price;
|
|
133
|
+
__privateGet(this, _state).settings.sharedBudget += convertedChange;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
reset() {
|
|
138
|
+
__privateSet(this, _state, {
|
|
139
|
+
schemaVersion: "1.0.0",
|
|
140
|
+
policy: __privateGet(this, _state).policy,
|
|
141
|
+
settings: null,
|
|
142
|
+
pendingDigests: []
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
export() {
|
|
146
|
+
return JSON.stringify(parse(AutoApprovalStateSchema, __privateGet(this, _state)));
|
|
147
|
+
}
|
|
148
|
+
getState() {
|
|
149
|
+
return parse(AutoApprovalStateSchema, __privateGet(this, _state));
|
|
150
|
+
}
|
|
151
|
+
getSettings() {
|
|
152
|
+
return __privateGet(this, _state).settings;
|
|
153
|
+
}
|
|
154
|
+
updateSettings(settings) {
|
|
155
|
+
const validatedSettings = parse(AutoApprovalSettingsSchema, settings);
|
|
156
|
+
__privateGet(this, _state).settings = validatedSettings;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
_state = new WeakMap();
|
|
160
|
+
_AutoApprovalManager_instances = new WeakSet();
|
|
161
|
+
matchesPolicy_fn = function(analysis) {
|
|
162
|
+
const issues = [];
|
|
163
|
+
if (analysis.issues) {
|
|
164
|
+
issues.push({ message: "Transaction analysis failed" });
|
|
165
|
+
return issues;
|
|
166
|
+
}
|
|
167
|
+
if (!analysis.result.operationType) {
|
|
168
|
+
issues.push({ message: "Operation type not found in Transaction" });
|
|
169
|
+
return issues;
|
|
170
|
+
}
|
|
171
|
+
const operation = __privateGet(this, _state).policy.operations.find(
|
|
172
|
+
(op) => op.id === analysis.result.operationType
|
|
173
|
+
);
|
|
174
|
+
if (!operation) {
|
|
175
|
+
issues.push({ message: "Operation not found in policy" });
|
|
176
|
+
return issues;
|
|
177
|
+
}
|
|
178
|
+
if (!operation.permissions.anyBalance) {
|
|
179
|
+
for (const flow of analysis.result.coinFlows.outflows) {
|
|
180
|
+
if (!operation.permissions.balances?.find((b) => b.coinType === flow.coinType)) {
|
|
181
|
+
issues.push({
|
|
182
|
+
message: `Operation does not have permission to use coin type ${flow.coinType}`
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
for (const obj of analysis.result.ownedObjects) {
|
|
188
|
+
if (isCoinType(obj.type)) {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
const accessLevel = analysis.result.accessLevel[obj.id];
|
|
192
|
+
if (!accessLevel) {
|
|
193
|
+
issues.push({ message: `Access level could not be determined for object ${obj.id}` });
|
|
194
|
+
}
|
|
195
|
+
const ownedObjectsPermission = operation.permissions.ownedObjects?.find(
|
|
196
|
+
(p) => p.objectType === obj.type
|
|
197
|
+
);
|
|
198
|
+
if (!ownedObjectsPermission) {
|
|
199
|
+
issues.push({ message: `No permission found for object ${obj.id}` });
|
|
200
|
+
} else if (!compareAccessLevel(ownedObjectsPermission.accessLevel, accessLevel)) {
|
|
201
|
+
issues.push({
|
|
202
|
+
message: `Insufficient access level for object ${obj.id}: required ${ownedObjectsPermission.accessLevel}, got ${accessLevel}`
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return issues;
|
|
207
|
+
function compareAccessLevel(required, actual) {
|
|
208
|
+
if (required === "read") {
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
if (required === "mutate") {
|
|
212
|
+
return actual === "mutate" || actual === "transfer";
|
|
213
|
+
}
|
|
214
|
+
return actual === "transfer";
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
canAutoApprove_fn = function(analysis) {
|
|
218
|
+
const issues = [];
|
|
219
|
+
if (!__privateGet(this, _state).settings) {
|
|
220
|
+
issues.push({ message: "No auto-approval settings configured" });
|
|
221
|
+
return issues;
|
|
222
|
+
}
|
|
223
|
+
if (analysis.issues) {
|
|
224
|
+
issues.push({ message: "Transaction analysis failed" });
|
|
225
|
+
return issues;
|
|
226
|
+
}
|
|
227
|
+
if (/* @__PURE__ */ new Date() > new Date(__privateGet(this, _state).settings.expiration)) {
|
|
228
|
+
issues.push({ message: "Auto-approval settings have expired" });
|
|
229
|
+
}
|
|
230
|
+
if (__privateGet(this, _state).settings.remainingTransactions !== null && __privateGet(this, _state).settings.remainingTransactions <= 0) {
|
|
231
|
+
issues.push({ message: "No remaining auto-approved transactions" });
|
|
232
|
+
}
|
|
233
|
+
if (!analysis.result.operationType || !__privateGet(this, _state).settings.approvedOperations.includes(analysis.result.operationType)) {
|
|
234
|
+
issues.push({ message: "Operation type not approved for auto-approval" });
|
|
235
|
+
}
|
|
236
|
+
for (const outflow of analysis.result.coinFlows.outflows) {
|
|
237
|
+
if (outflow.amount <= 0n) {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
if (__privateGet(this, _state).settings.coinBudgets[outflow.coinType] !== void 0) {
|
|
241
|
+
const coinBudget = __privateGet(this, _state).settings.coinBudgets[outflow.coinType];
|
|
242
|
+
if (coinBudget) {
|
|
243
|
+
if (BigInt(coinBudget) < outflow.amount) {
|
|
244
|
+
issues.push({
|
|
245
|
+
message: `Insufficient budget for coin type ${outflow.coinType}`
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
} else {
|
|
250
|
+
const coinAmount = analysis.result.coinValues.coinTypes.find(
|
|
251
|
+
(ct) => ct.coinType === outflow.coinType
|
|
252
|
+
);
|
|
253
|
+
if (!coinAmount) {
|
|
254
|
+
issues.push({
|
|
255
|
+
message: `No budget configured for coin type ${outflow.coinType}`
|
|
256
|
+
});
|
|
257
|
+
} else if ((__privateGet(this, _state).settings.sharedBudget ?? 0) < coinAmount.convertedAmount) {
|
|
258
|
+
issues.push({
|
|
259
|
+
message: `Insufficient budget for coin type ${outflow.coinType}`
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return issues;
|
|
265
|
+
};
|
|
266
|
+
revertCoinFlows_fn = function(analysis) {
|
|
267
|
+
if (!__privateGet(this, _state).settings) {
|
|
268
|
+
throw new Error("No auto-approval settings configured");
|
|
269
|
+
}
|
|
270
|
+
if (!analysis.result) {
|
|
271
|
+
throw new Error("Transaction analysis failed");
|
|
272
|
+
}
|
|
273
|
+
for (const outflow of analysis.result.coinFlows.outflows) {
|
|
274
|
+
if (__privateGet(this, _state).settings?.coinBudgets[outflow.coinType] !== void 0) {
|
|
275
|
+
const currentBudget = BigInt(__privateGet(this, _state).settings?.coinBudgets[outflow.coinType] ?? "0");
|
|
276
|
+
const newBalance = currentBudget + outflow.amount;
|
|
277
|
+
__privateGet(this, _state).settings.coinBudgets[outflow.coinType] = newBalance.toString();
|
|
278
|
+
} else {
|
|
279
|
+
if (__privateGet(this, _state).settings.sharedBudget === null) {
|
|
280
|
+
throw new Error("No budget available for coin type " + outflow.coinType);
|
|
281
|
+
}
|
|
282
|
+
const coinValue = analysis.result.coinValues.coinTypes.find(
|
|
283
|
+
(ct) => ct.coinType === outflow.coinType
|
|
284
|
+
);
|
|
285
|
+
if (!coinValue) {
|
|
286
|
+
throw new Error("No value available for coin type " + outflow.coinType);
|
|
287
|
+
}
|
|
288
|
+
__privateGet(this, _state).settings.sharedBudget += coinValue.convertedAmount;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
removePendingDigest_fn = function(digest) {
|
|
293
|
+
const pendingIndex = __privateGet(this, _state).pendingDigests.indexOf(digest);
|
|
294
|
+
if (pendingIndex >= 0) {
|
|
295
|
+
__privateGet(this, _state).pendingDigests.splice(pendingIndex, 1);
|
|
296
|
+
} else {
|
|
297
|
+
throw new Error(`Transaction with digest ${digest} not found in pending digests`);
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
const parsedCoinType = parseStructTag("0x2::coin::Coin");
|
|
301
|
+
function isCoinType(type) {
|
|
302
|
+
const parsedType = parseStructTag(type);
|
|
303
|
+
return parsedType.address === parsedCoinType.address && parsedType.module === parsedCoinType.module && parsedType.name === parsedCoinType.name && parsedType.typeParams.length === 1;
|
|
304
|
+
}
|
|
305
|
+
export {
|
|
306
|
+
AutoApprovalManager
|
|
307
|
+
};
|
|
308
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/auto-approvals/manager.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Experimental_HaneulClientTypes } from '@haneullabs/haneul/experimental';\nimport { parse, safeParse } from 'valibot';\nimport type { AutoApprovalState } from './schemas/state.js';\nimport { AutoApprovalStateSchema } from './schemas/state.js';\nimport type { AutoApprovalSettings } from './schemas/policy.js';\nimport { AutoApprovalPolicySchema, AutoApprovalSettingsSchema } from './schemas/policy.js';\nimport { parseStructTag } from '@haneullabs/haneul/utils';\nimport type { AutoApprovalResult } from './analyzer.js';\n\nexport interface AutoApprovalManagerOptions {\n\tpolicy: string;\n\tstate: string | null;\n}\n\nexport interface AutoApprovalIssue {\n\tmessage: string;\n}\n\nexport interface AutoApprovalCheck {\n\tmatchesPolicy: boolean;\n\tcanAutoApprove: boolean;\n\tpolicyIssues: AutoApprovalIssue[];\n\tsettingsIssues: AutoApprovalIssue[];\n\tanalysisIssues: AutoApprovalIssue[];\n}\n\nexport class AutoApprovalManager {\n\t#state: AutoApprovalState;\n\n\tconstructor(options: AutoApprovalManagerOptions) {\n\t\tlet state: AutoApprovalState | null = null;\n\n\t\tif (options.state) {\n\t\t\tconst parseResult = safeParse(AutoApprovalStateSchema, JSON.parse(options.state));\n\t\t\t// TODO: how do we want to handle failures\n\t\t\tif (parseResult.success) {\n\t\t\t\tconst providedPolicy = parse(AutoApprovalPolicySchema, JSON.parse(options.policy));\n\t\t\t\tconst currentPolicy = parseResult.output.policy;\n\n\t\t\t\tif (JSON.stringify(currentPolicy) === JSON.stringify(providedPolicy)) {\n\t\t\t\t\tstate = parseResult.output;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis.#state =\n\t\t\tstate ??\n\t\t\tparse(AutoApprovalStateSchema, {\n\t\t\t\tschemaVersion: '1.0.0',\n\t\t\t\tpolicy: parse(AutoApprovalPolicySchema, JSON.parse(options.policy)),\n\t\t\t\tsettings: null,\n\t\t\t\tpendingDigests: [],\n\t\t\t} satisfies AutoApprovalState);\n\t}\n\n\tcheckTransaction(analysis: AutoApprovalResult): AutoApprovalCheck {\n\t\tconst results: AutoApprovalCheck = {\n\t\t\tmatchesPolicy: false,\n\t\t\tcanAutoApprove: false,\n\t\t\tanalysisIssues: [...(analysis.issues ?? [])],\n\t\t\tpolicyIssues: [],\n\t\t\tsettingsIssues: [],\n\t\t};\n\n\t\tif (results.analysisIssues.length > 0) {\n\t\t\treturn results;\n\t\t}\n\n\t\tconst policyIssues = this.#matchesPolicy(analysis);\n\n\t\tif (policyIssues.length > 0) {\n\t\t\tresults.policyIssues = policyIssues;\n\t\t\treturn results;\n\t\t} else {\n\t\t\tresults.matchesPolicy = true;\n\t\t}\n\n\t\tconst settingsIssues = this.#canAutoApprove(analysis);\n\n\t\tif (settingsIssues.length > 0) {\n\t\t\tresults.settingsIssues = settingsIssues;\n\t\t\treturn results;\n\t\t} else {\n\t\t\tresults.canAutoApprove = true;\n\t\t}\n\n\t\treturn results;\n\t}\n\n\t#matchesPolicy(analysis: AutoApprovalResult): AutoApprovalIssue[] {\n\t\tconst issues: AutoApprovalIssue[] = [];\n\n\t\tif (analysis.issues) {\n\t\t\tissues.push({ message: 'Transaction analysis failed' });\n\t\t\treturn issues;\n\t\t}\n\n\t\tif (!analysis.result.operationType) {\n\t\t\tissues.push({ message: 'Operation type not found in Transaction' });\n\n\t\t\treturn issues;\n\t\t}\n\n\t\tconst operation = this.#state.policy.operations.find(\n\t\t\t(op) => op.id === analysis.result.operationType,\n\t\t);\n\n\t\tif (!operation) {\n\t\t\tissues.push({ message: 'Operation not found in policy' });\n\t\t\treturn issues;\n\t\t}\n\n\t\tif (!operation.permissions.anyBalance) {\n\t\t\tfor (const flow of analysis.result.coinFlows.outflows) {\n\t\t\t\tif (!operation.permissions.balances?.find((b) => b.coinType === flow.coinType)) {\n\t\t\t\t\tissues.push({\n\t\t\t\t\t\tmessage: `Operation does not have permission to use coin type ${flow.coinType}`,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const obj of analysis.result.ownedObjects) {\n\t\t\tif (isCoinType(obj.type)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst accessLevel = analysis.result.accessLevel[obj.id];\n\n\t\t\tif (!accessLevel) {\n\t\t\t\tissues.push({ message: `Access level could not be determined for object ${obj.id}` });\n\t\t\t}\n\n\t\t\tconst ownedObjectsPermission = operation.permissions.ownedObjects?.find(\n\t\t\t\t(p) => p.objectType === obj.type,\n\t\t\t);\n\n\t\t\tif (!ownedObjectsPermission) {\n\t\t\t\tissues.push({ message: `No permission found for object ${obj.id}` });\n\t\t\t} else if (!compareAccessLevel(ownedObjectsPermission.accessLevel, accessLevel)) {\n\t\t\t\tissues.push({\n\t\t\t\t\tmessage: `Insufficient access level for object ${obj.id}: required ${ownedObjectsPermission.accessLevel}, got ${accessLevel}`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn issues;\n\n\t\tfunction compareAccessLevel(\n\t\t\trequired: 'read' | 'mutate' | 'transfer',\n\t\t\tactual: 'read' | 'mutate' | 'transfer',\n\t\t): boolean {\n\t\t\tif (required === 'read') {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (required === 'mutate') {\n\t\t\t\treturn actual === 'mutate' || actual === 'transfer';\n\t\t\t}\n\t\t\treturn actual === 'transfer';\n\t\t}\n\t}\n\n\t#canAutoApprove(analysis: AutoApprovalResult): AutoApprovalIssue[] {\n\t\tconst issues: AutoApprovalIssue[] = [];\n\n\t\tif (!this.#state.settings) {\n\t\t\tissues.push({ message: 'No auto-approval settings configured' });\n\t\t\treturn issues;\n\t\t}\n\n\t\tif (analysis.issues) {\n\t\t\tissues.push({ message: 'Transaction analysis failed' });\n\t\t\treturn issues;\n\t\t}\n\n\t\tif (new Date() > new Date(this.#state.settings.expiration)) {\n\t\t\tissues.push({ message: 'Auto-approval settings have expired' });\n\t\t}\n\n\t\tif (\n\t\t\tthis.#state.settings.remainingTransactions !== null &&\n\t\t\tthis.#state.settings.remainingTransactions <= 0\n\t\t) {\n\t\t\tissues.push({ message: 'No remaining auto-approved transactions' });\n\t\t}\n\n\t\tif (\n\t\t\t!analysis.result.operationType ||\n\t\t\t!this.#state.settings.approvedOperations.includes(analysis.result.operationType)\n\t\t) {\n\t\t\tissues.push({ message: 'Operation type not approved for auto-approval' });\n\t\t}\n\n\t\tfor (const outflow of analysis.result.coinFlows.outflows) {\n\t\t\tif (outflow.amount <= 0n) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (this.#state.settings.coinBudgets[outflow.coinType] !== undefined) {\n\t\t\t\tconst coinBudget = this.#state.settings.coinBudgets[outflow.coinType];\n\n\t\t\t\tif (coinBudget) {\n\t\t\t\t\tif (BigInt(coinBudget) < outflow.amount) {\n\t\t\t\t\t\tissues.push({\n\t\t\t\t\t\t\tmessage: `Insufficient budget for coin type ${outflow.coinType}`,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst coinAmount = analysis.result.coinValues.coinTypes.find(\n\t\t\t\t\t(ct) => ct.coinType === outflow.coinType,\n\t\t\t\t);\n\n\t\t\t\tif (!coinAmount) {\n\t\t\t\t\tissues.push({\n\t\t\t\t\t\tmessage: `No budget configured for coin type ${outflow.coinType}`,\n\t\t\t\t\t});\n\t\t\t\t} else if ((this.#state.settings.sharedBudget ?? 0) < coinAmount.convertedAmount) {\n\t\t\t\t\tissues.push({\n\t\t\t\t\t\tmessage: `Insufficient budget for coin type ${outflow.coinType}`,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn issues;\n\t}\n\n\t// TODO: we should ensure that only 1 tx is pending at a time, and pending txs can't increase budgets\n\tcommitTransaction(analysis: AutoApprovalResult): void {\n\t\tif (!this.#state.settings) {\n\t\t\tthrow new Error('No auto-approval settings configured');\n\t\t}\n\n\t\tif (!analysis.result) {\n\t\t\tthrow new Error('Transaction analysis failed');\n\t\t}\n\n\t\tif (this.#state.settings.remainingTransactions !== null && this.#state.settings) {\n\t\t\tthis.#state.settings.remainingTransactions = Math.max(\n\t\t\t\t0,\n\t\t\t\tthis.#state.settings.remainingTransactions - 1,\n\t\t\t);\n\t\t}\n\n\t\tfor (const outflow of analysis.result.coinFlows.outflows) {\n\t\t\tif (this.#state.settings.coinBudgets[outflow.coinType] !== undefined) {\n\t\t\t\tconst currentBudget = BigInt(this.#state.settings?.coinBudgets[outflow.coinType] ?? '0');\n\t\t\t\tconst newBalance = currentBudget - outflow.amount;\n\t\t\t\tthis.#state.settings.coinBudgets[outflow.coinType] = newBalance.toString();\n\t\t\t} else {\n\t\t\t\tif (this.#state.settings.sharedBudget === null) {\n\t\t\t\t\tthrow new Error('No budget available for coin type ' + outflow.coinType);\n\t\t\t\t}\n\n\t\t\t\tconst coinValue = analysis.result.coinValues.coinTypes.find(\n\t\t\t\t\t(ct) => ct.coinType === outflow.coinType,\n\t\t\t\t);\n\n\t\t\t\tif (!coinValue) {\n\t\t\t\t\tthrow new Error('No value available for coin type ' + outflow.coinType);\n\t\t\t\t}\n\n\t\t\t\tthis.#state.settings.sharedBudget -= coinValue.convertedAmount;\n\t\t\t}\n\t\t}\n\n\t\tthis.#state.pendingDigests.push(analysis.result.digest);\n\t}\n\n\trevertTransaction(analysis: AutoApprovalResult): void {\n\t\tif (analysis.result?.digest) {\n\t\t\tthis.#removePendingDigest(analysis.result?.digest);\n\t\t}\n\n\t\tif (this.#state.settings?.remainingTransactions !== null && this.#state.settings) {\n\t\t\tthis.#state.settings.remainingTransactions += 1;\n\t\t}\n\n\t\tthis.#revertCoinFlows(analysis);\n\t}\n\n\t#revertCoinFlows(analysis: AutoApprovalResult): void {\n\t\tif (!this.#state.settings) {\n\t\t\tthrow new Error('No auto-approval settings configured');\n\t\t}\n\n\t\tif (!analysis.result) {\n\t\t\tthrow new Error('Transaction analysis failed');\n\t\t}\n\n\t\tfor (const outflow of analysis.result.coinFlows.outflows) {\n\t\t\tif (this.#state.settings?.coinBudgets[outflow.coinType] !== undefined) {\n\t\t\t\tconst currentBudget = BigInt(this.#state.settings?.coinBudgets[outflow.coinType] ?? '0');\n\t\t\t\tconst newBalance = currentBudget + outflow.amount;\n\t\t\t\tthis.#state.settings.coinBudgets[outflow.coinType] = newBalance.toString();\n\t\t\t} else {\n\t\t\t\tif (this.#state.settings.sharedBudget === null) {\n\t\t\t\t\tthrow new Error('No budget available for coin type ' + outflow.coinType);\n\t\t\t\t}\n\n\t\t\t\tconst coinValue = analysis.result.coinValues.coinTypes.find(\n\t\t\t\t\t(ct) => ct.coinType === outflow.coinType,\n\t\t\t\t);\n\n\t\t\t\tif (!coinValue) {\n\t\t\t\t\tthrow new Error('No value available for coin type ' + outflow.coinType);\n\t\t\t\t}\n\n\t\t\t\tthis.#state.settings.sharedBudget += coinValue.convertedAmount;\n\t\t\t}\n\t\t}\n\t}\n\n\t#removePendingDigest(digest: string): void {\n\t\tconst pendingIndex = this.#state.pendingDigests.indexOf(digest);\n\t\tif (pendingIndex >= 0) {\n\t\t\tthis.#state.pendingDigests.splice(pendingIndex, 1);\n\t\t} else {\n\t\t\tthrow new Error(`Transaction with digest ${digest} not found in pending digests`);\n\t\t}\n\t}\n\n\tapplyTransactionEffects(\n\t\tanalysis: AutoApprovalResult,\n\t\tresult: Experimental_HaneulClientTypes.TransactionResponse,\n\t): void {\n\t\tthis.#removePendingDigest(result.digest);\n\n\t\tif (!this.#state.settings) {\n\t\t\tthrow new Error('No auto-approval settings configured');\n\t\t}\n\n\t\tif (!analysis.result) {\n\t\t\tthrow new Error('Transaction analysis failed');\n\t\t}\n\n\t\t// Revert coin flows and use real balance changes instead\n\t\tthis.#revertCoinFlows(analysis);\n\n\t\tfor (const change of result.balanceChanges) {\n\t\t\tif (this.#state.settings.coinBudgets[change.coinType] !== undefined) {\n\t\t\t\tconst currentBudget = BigInt(this.#state.settings?.coinBudgets[change.coinType] ?? '0');\n\t\t\t\tconst newBalance = currentBudget + BigInt(change.amount);\n\t\t\t\tif (this.#state.settings) {\n\t\t\t\t\tthis.#state.settings.coinBudgets[change.coinType] = newBalance.toString();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (this.#state.settings.sharedBudget === null) {\n\t\t\t\t\tthrow new Error('No budget available for coin type ' + change.coinType);\n\t\t\t\t}\n\n\t\t\t\tconst coinValue = analysis.result.coinValues.coinTypes.find(\n\t\t\t\t\t(ct) => ct.coinType === change.coinType,\n\t\t\t\t);\n\n\t\t\t\tif (!coinValue) {\n\t\t\t\t\tthrow new Error('No value available for coin type ' + change.coinType);\n\t\t\t\t}\n\n\t\t\t\tconst convertedChange =\n\t\t\t\t\t(Number(change.amount) / 10 ** coinValue.decimals) * coinValue.price;\n\n\t\t\t\tthis.#state.settings.sharedBudget += convertedChange;\n\t\t\t}\n\t\t}\n\t}\n\n\treset() {\n\t\tthis.#state = {\n\t\t\tschemaVersion: '1.0.0',\n\t\t\tpolicy: this.#state.policy,\n\t\t\tsettings: null,\n\t\t\tpendingDigests: [],\n\t\t};\n\t}\n\n\texport(): string {\n\t\treturn JSON.stringify(parse(AutoApprovalStateSchema, this.#state));\n\t}\n\n\tgetState(): AutoApprovalState {\n\t\treturn parse(AutoApprovalStateSchema, this.#state);\n\t}\n\n\tgetSettings(): AutoApprovalSettings | null {\n\t\treturn this.#state.settings;\n\t}\n\n\tupdateSettings(settings: AutoApprovalSettings): void {\n\t\tconst validatedSettings = parse(AutoApprovalSettingsSchema, settings);\n\t\tthis.#state.settings = validatedSettings;\n\t}\n}\n\nconst parsedCoinType = parseStructTag('0x2::coin::Coin');\n\nfunction isCoinType(type: string): boolean {\n\tconst parsedType = parseStructTag(type);\n\treturn (\n\t\tparsedType.address === parsedCoinType.address &&\n\t\tparsedType.module === parsedCoinType.module &&\n\t\tparsedType.name === parsedCoinType.name &&\n\t\tparsedType.typeParams.length === 1\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAAA;AAIA,SAAS,OAAO,iBAAiB;AAEjC,SAAS,+BAA+B;AAExC,SAAS,0BAA0B,kCAAkC;AACrE,SAAS,sBAAsB;AAoBxB,MAAM,oBAAoB;AAAA,EAGhC,YAAY,SAAqC;AAH3C;AACN;AAGC,QAAI,QAAkC;AAEtC,QAAI,QAAQ,OAAO;AAClB,YAAM,cAAc,UAAU,yBAAyB,KAAK,MAAM,QAAQ,KAAK,CAAC;AAEhF,UAAI,YAAY,SAAS;AACxB,cAAM,iBAAiB,MAAM,0BAA0B,KAAK,MAAM,QAAQ,MAAM,CAAC;AACjF,cAAM,gBAAgB,YAAY,OAAO;AAEzC,YAAI,KAAK,UAAU,aAAa,MAAM,KAAK,UAAU,cAAc,GAAG;AACrE,kBAAQ,YAAY;AAAA,QACrB;AAAA,MACD;AAAA,IACD;AAEA,uBAAK,QACJ,SACA,MAAM,yBAAyB;AAAA,MAC9B,eAAe;AAAA,MACf,QAAQ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D;AAEA,yBAAoB,SAAC,QAAsB;AAC1C,QAAM,eAAe,mBAAK,QAAO,eAAe,QAAQ,MAAM;AAC9D,MAAI,gBAAgB,GAAG;AACtB,uBAAK,QAAO,eAAe,OAAO,cAAc,CAAC;AAAA,EAClD,OAAO;AACN,UAAM,IAAI,MAAM,2BAA2B,MAAM,+BAA+B;AAAA,EACjF;AACD;AA0ED,MAAM,iBAAiB,eAAe,iBAAiB;AAEvD,SAAS,WAAW,MAAuB;AAC1C,QAAM,aAAa,eAAe,IAAI;AACtC,SACC,WAAW,YAAY,eAAe,WACtC,WAAW,WAAW,eAAe,UACrC,WAAW,SAAS,eAAe,QACnC,WAAW,WAAW,WAAW;AAEnC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { AutoApprovalPolicySchema, AutoApprovalSettingsSchema } from './policy.js';
|
|
2
|
+
export type { AutoApprovalPolicy, AutoApprovalSettings, AutoApprovalOperation, PolicyPermission, } from './policy.js';
|
|
3
|
+
export { AutoApprovalStateSchema } from './state.js';
|
|
4
|
+
export type { AutoApprovalState } from './state.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AutoApprovalPolicySchema, AutoApprovalSettingsSchema } from "./policy.js";
|
|
2
|
+
import { AutoApprovalStateSchema } from "./state.js";
|
|
3
|
+
export {
|
|
4
|
+
AutoApprovalPolicySchema,
|
|
5
|
+
AutoApprovalSettingsSchema,
|
|
6
|
+
AutoApprovalStateSchema
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/auto-approvals/schemas/index.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nexport { AutoApprovalPolicySchema, AutoApprovalSettingsSchema } from './policy.js';\nexport type {\n\tAutoApprovalPolicy,\n\tAutoApprovalSettings,\n\tAutoApprovalOperation,\n\tPolicyPermission,\n} from './policy.js';\n\nexport { AutoApprovalStateSchema } from './state.js';\nexport type { AutoApprovalState } from './state.js';\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,0BAA0B,kCAAkC;AAQrE,SAAS,+BAA+B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
declare const ObjectTypePermissionSchema: v.ObjectSchema<{
|
|
3
|
+
readonly $kind: v.LiteralSchema<"ObjectType", undefined>;
|
|
4
|
+
readonly objectType: v.StringSchema<undefined>;
|
|
5
|
+
readonly accessLevel: v.UnionSchema<[v.LiteralSchema<"read", undefined>, v.LiteralSchema<"mutate", undefined>, v.LiteralSchema<"transfer", undefined>], undefined>;
|
|
6
|
+
readonly description: v.StringSchema<undefined>;
|
|
7
|
+
}, undefined>;
|
|
8
|
+
declare const CoinBalancePermissionSchema: v.ObjectSchema<{
|
|
9
|
+
readonly $kind: v.LiteralSchema<"CoinBalance", undefined>;
|
|
10
|
+
readonly coinType: v.StringSchema<undefined>;
|
|
11
|
+
readonly description: v.StringSchema<undefined>;
|
|
12
|
+
}, undefined>;
|
|
13
|
+
declare const AnyBalancesPermissionSchema: v.ObjectSchema<{
|
|
14
|
+
readonly $kind: v.LiteralSchema<"AnyBalance", undefined>;
|
|
15
|
+
readonly description: v.StringSchema<undefined>;
|
|
16
|
+
}, undefined>;
|
|
17
|
+
export type PolicyPermission = v.InferOutput<typeof CoinBalancePermissionSchema | typeof AnyBalancesPermissionSchema | typeof ObjectTypePermissionSchema>;
|
|
18
|
+
declare const AutoApprovalOperationSchema: v.ObjectSchema<{
|
|
19
|
+
readonly id: v.StringSchema<undefined>;
|
|
20
|
+
readonly description: v.StringSchema<undefined>;
|
|
21
|
+
readonly permissions: v.ObjectSchema<{
|
|
22
|
+
readonly ownedObjects: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
23
|
+
readonly $kind: v.LiteralSchema<"ObjectType", undefined>;
|
|
24
|
+
readonly objectType: v.StringSchema<undefined>;
|
|
25
|
+
readonly accessLevel: v.UnionSchema<[v.LiteralSchema<"read", undefined>, v.LiteralSchema<"mutate", undefined>, v.LiteralSchema<"transfer", undefined>], undefined>;
|
|
26
|
+
readonly description: v.StringSchema<undefined>;
|
|
27
|
+
}, undefined>, undefined>, undefined>;
|
|
28
|
+
readonly balances: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
29
|
+
readonly $kind: v.LiteralSchema<"CoinBalance", undefined>;
|
|
30
|
+
readonly coinType: v.StringSchema<undefined>;
|
|
31
|
+
readonly description: v.StringSchema<undefined>;
|
|
32
|
+
}, undefined>, undefined>, undefined>;
|
|
33
|
+
readonly anyBalance: v.OptionalSchema<v.ObjectSchema<{
|
|
34
|
+
readonly $kind: v.LiteralSchema<"AnyBalance", undefined>;
|
|
35
|
+
readonly description: v.StringSchema<undefined>;
|
|
36
|
+
}, undefined>, undefined>;
|
|
37
|
+
}, undefined>;
|
|
38
|
+
}, undefined>;
|
|
39
|
+
export declare const AutoApprovalSettingsSchema: v.LooseObjectSchema<{
|
|
40
|
+
readonly approvedOperations: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
41
|
+
readonly expiration: v.NumberSchema<undefined>;
|
|
42
|
+
readonly remainingTransactions: v.NullableSchema<v.NumberSchema<undefined>, undefined>;
|
|
43
|
+
readonly sharedBudget: v.NullableSchema<v.NumberSchema<undefined>, undefined>;
|
|
44
|
+
readonly coinBudgets: v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>;
|
|
45
|
+
}, undefined>;
|
|
46
|
+
export declare const AutoApprovalPolicySchema: v.ObjectSchema<{
|
|
47
|
+
readonly schemaVersion: v.LiteralSchema<"1.0.0", undefined>;
|
|
48
|
+
readonly operations: v.ArraySchema<v.ObjectSchema<{
|
|
49
|
+
readonly id: v.StringSchema<undefined>;
|
|
50
|
+
readonly description: v.StringSchema<undefined>;
|
|
51
|
+
readonly permissions: v.ObjectSchema<{
|
|
52
|
+
readonly ownedObjects: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
53
|
+
readonly $kind: v.LiteralSchema<"ObjectType", undefined>;
|
|
54
|
+
readonly objectType: v.StringSchema<undefined>;
|
|
55
|
+
readonly accessLevel: v.UnionSchema<[v.LiteralSchema<"read", undefined>, v.LiteralSchema<"mutate", undefined>, v.LiteralSchema<"transfer", undefined>], undefined>;
|
|
56
|
+
readonly description: v.StringSchema<undefined>;
|
|
57
|
+
}, undefined>, undefined>, undefined>;
|
|
58
|
+
readonly balances: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
59
|
+
readonly $kind: v.LiteralSchema<"CoinBalance", undefined>;
|
|
60
|
+
readonly coinType: v.StringSchema<undefined>;
|
|
61
|
+
readonly description: v.StringSchema<undefined>;
|
|
62
|
+
}, undefined>, undefined>, undefined>;
|
|
63
|
+
readonly anyBalance: v.OptionalSchema<v.ObjectSchema<{
|
|
64
|
+
readonly $kind: v.LiteralSchema<"AnyBalance", undefined>;
|
|
65
|
+
readonly description: v.StringSchema<undefined>;
|
|
66
|
+
}, undefined>, undefined>;
|
|
67
|
+
}, undefined>;
|
|
68
|
+
}, undefined>, undefined>;
|
|
69
|
+
readonly suggestedSettings: v.OptionalSchema<Omit<v.LooseObjectSchema<{
|
|
70
|
+
readonly approvedOperations: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
71
|
+
readonly expiration: v.NumberSchema<undefined>;
|
|
72
|
+
readonly remainingTransactions: v.NullableSchema<v.NumberSchema<undefined>, undefined>;
|
|
73
|
+
readonly sharedBudget: v.NullableSchema<v.NumberSchema<undefined>, undefined>;
|
|
74
|
+
readonly coinBudgets: v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>;
|
|
75
|
+
}, undefined>, "entries" | "~types" | "~run" | "~standard"> & {
|
|
76
|
+
readonly entries: {
|
|
77
|
+
readonly approvedOperations: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
|
|
78
|
+
readonly expiration: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
|
|
79
|
+
readonly remainingTransactions: v.OptionalSchema<v.NullableSchema<v.NumberSchema<undefined>, undefined>, undefined>;
|
|
80
|
+
readonly sharedBudget: v.OptionalSchema<v.NullableSchema<v.NumberSchema<undefined>, undefined>, undefined>;
|
|
81
|
+
readonly coinBudgets: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>, undefined>;
|
|
82
|
+
};
|
|
83
|
+
readonly "~standard": v.StandardProps<{
|
|
84
|
+
approvedOperations?: string[] | undefined;
|
|
85
|
+
expiration?: number | undefined;
|
|
86
|
+
remainingTransactions?: number | null | undefined;
|
|
87
|
+
sharedBudget?: number | null | undefined;
|
|
88
|
+
coinBudgets?: {
|
|
89
|
+
[x: string]: string;
|
|
90
|
+
} | undefined;
|
|
91
|
+
} & {
|
|
92
|
+
[key: string]: unknown;
|
|
93
|
+
}, {
|
|
94
|
+
approvedOperations?: string[] | undefined;
|
|
95
|
+
expiration?: number | undefined;
|
|
96
|
+
remainingTransactions?: number | null | undefined;
|
|
97
|
+
sharedBudget?: number | null | undefined;
|
|
98
|
+
coinBudgets?: {
|
|
99
|
+
[x: string]: string;
|
|
100
|
+
} | undefined;
|
|
101
|
+
} & {
|
|
102
|
+
[key: string]: unknown;
|
|
103
|
+
}>;
|
|
104
|
+
readonly "~run": (dataset: v.UnknownDataset, config: v.Config<v.BaseIssue<unknown>>) => v.OutputDataset<{
|
|
105
|
+
approvedOperations?: string[] | undefined;
|
|
106
|
+
expiration?: number | undefined;
|
|
107
|
+
remainingTransactions?: number | null | undefined;
|
|
108
|
+
sharedBudget?: number | null | undefined;
|
|
109
|
+
coinBudgets?: {
|
|
110
|
+
[x: string]: string;
|
|
111
|
+
} | undefined;
|
|
112
|
+
} & {
|
|
113
|
+
[key: string]: unknown;
|
|
114
|
+
}, v.StringIssue | v.ArrayIssue | v.NumberIssue | v.RecordIssue | v.LooseObjectIssue>;
|
|
115
|
+
readonly "~types"?: {
|
|
116
|
+
readonly input: {
|
|
117
|
+
approvedOperations?: string[] | undefined;
|
|
118
|
+
expiration?: number | undefined;
|
|
119
|
+
remainingTransactions?: number | null | undefined;
|
|
120
|
+
sharedBudget?: number | null | undefined;
|
|
121
|
+
coinBudgets?: {
|
|
122
|
+
[x: string]: string;
|
|
123
|
+
} | undefined;
|
|
124
|
+
} & {
|
|
125
|
+
[key: string]: unknown;
|
|
126
|
+
};
|
|
127
|
+
readonly output: {
|
|
128
|
+
approvedOperations?: string[] | undefined;
|
|
129
|
+
expiration?: number | undefined;
|
|
130
|
+
remainingTransactions?: number | null | undefined;
|
|
131
|
+
sharedBudget?: number | null | undefined;
|
|
132
|
+
coinBudgets?: {
|
|
133
|
+
[x: string]: string;
|
|
134
|
+
} | undefined;
|
|
135
|
+
} & {
|
|
136
|
+
[key: string]: unknown;
|
|
137
|
+
};
|
|
138
|
+
readonly issue: v.StringIssue | v.ArrayIssue | v.NumberIssue | v.RecordIssue | v.LooseObjectIssue;
|
|
139
|
+
} | undefined;
|
|
140
|
+
}, undefined>;
|
|
141
|
+
}, undefined>;
|
|
142
|
+
export type AutoApprovalSettings = v.InferOutput<typeof AutoApprovalSettingsSchema>;
|
|
143
|
+
export type AutoApprovalPolicy = v.InferOutput<typeof AutoApprovalPolicySchema>;
|
|
144
|
+
export type AutoApprovalOperation = v.InferOutput<typeof AutoApprovalOperationSchema>;
|
|
145
|
+
export {};
|