@pushchain/core 6.0.26 → 6.0.27-alpha.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.
Files changed (171) hide show
  1. package/AGW.md +226 -0
  2. package/CHANGELOG.md +18 -0
  3. package/README.md +2 -0
  4. package/package.json +7 -1
  5. package/src/lib/agentic/agentic.d.ts +23 -0
  6. package/src/lib/agentic/agentic.js +51 -0
  7. package/src/lib/agentic/agentic.types.d.ts +414 -0
  8. package/src/lib/agentic/agentic.types.js +3 -0
  9. package/src/lib/agentic/capabilities.d.ts +37 -0
  10. package/src/lib/agentic/capabilities.js +64 -0
  11. package/src/lib/agentic/chain.d.ts +3 -0
  12. package/src/lib/agentic/chain.js +15 -0
  13. package/src/lib/agentic/codec/abi-layout.d.ts +20 -0
  14. package/src/lib/agentic/codec/abi-layout.js +168 -0
  15. package/src/lib/agentic/codec/defaults.d.ts +51 -0
  16. package/src/lib/agentic/codec/defaults.js +53 -0
  17. package/src/lib/agentic/codec/ids.d.ts +35 -0
  18. package/src/lib/agentic/codec/ids.js +74 -0
  19. package/src/lib/agentic/codec/native.d.ts +73 -0
  20. package/src/lib/agentic/codec/native.js +341 -0
  21. package/src/lib/agentic/codec/pins.d.ts +20 -0
  22. package/src/lib/agentic/codec/pins.js +29 -0
  23. package/src/lib/agentic/codec/rules.d.ts +45 -0
  24. package/src/lib/agentic/codec/rules.js +110 -0
  25. package/src/lib/agentic/codec/selectors.d.ts +19 -0
  26. package/src/lib/agentic/codec/selectors.js +60 -0
  27. package/src/lib/agentic/codec/session.d.ts +54 -0
  28. package/src/lib/agentic/codec/session.js +65 -0
  29. package/src/lib/agentic/codec/svm-accounts.d.ts +35 -0
  30. package/src/lib/agentic/codec/svm-accounts.js +68 -0
  31. package/src/lib/agentic/codec/svm-idl.d.ts +11 -0
  32. package/src/lib/agentic/codec/svm-idl.js +226 -0
  33. package/src/lib/agentic/codec/svm-terms.d.ts +157 -0
  34. package/src/lib/agentic/codec/svm-terms.js +246 -0
  35. package/src/lib/agentic/codec/universal-terms.d.ts +82 -0
  36. package/src/lib/agentic/codec/universal-terms.js +43 -0
  37. package/src/lib/agentic/codec/universal.d.ts +14 -0
  38. package/src/lib/agentic/codec/universal.js +173 -0
  39. package/src/lib/agentic/constants.d.ts +12 -0
  40. package/src/lib/agentic/constants.js +16 -0
  41. package/src/lib/agentic/context.d.ts +29 -0
  42. package/src/lib/agentic/context.js +56 -0
  43. package/src/lib/agentic/contracts/abi/v6/agent-validator.d.ts +105 -0
  44. package/src/lib/agentic/contracts/abi/v6/agent-validator.js +149 -0
  45. package/src/lib/agentic/contracts/abi/v6/agw-factory.d.ts +1146 -0
  46. package/src/lib/agentic/contracts/abi/v6/agw-factory.js +1499 -0
  47. package/src/lib/agentic/contracts/abi/v6/agw.d.ts +1306 -0
  48. package/src/lib/agentic/contracts/abi/v6/agw.js +1713 -0
  49. package/src/lib/agentic/contracts/abi/v6/index.d.ts +6 -0
  50. package/src/lib/agentic/contracts/abi/v6/index.js +17 -0
  51. package/src/lib/agentic/contracts/abi/v6/smart-session.d.ts +1493 -0
  52. package/src/lib/agentic/contracts/abi/v6/smart-session.js +1965 -0
  53. package/src/lib/agentic/contracts/abi/v6/universal-rules-policy.d.ts +1661 -0
  54. package/src/lib/agentic/contracts/abi/v6/universal-rules-policy.js +2187 -0
  55. package/src/lib/agentic/contracts/donut-v6.d.ts +11 -0
  56. package/src/lib/agentic/contracts/donut-v6.js +15 -0
  57. package/src/lib/agentic/contracts/prc20-metadata.d.ts +26 -0
  58. package/src/lib/agentic/contracts/prc20-metadata.js +87 -0
  59. package/src/lib/agentic/contracts/reader.d.ts +35 -0
  60. package/src/lib/agentic/contracts/reader.js +16 -0
  61. package/src/lib/agentic/contracts/v6.d.ts +5739 -0
  62. package/src/lib/agentic/contracts/v6.js +343 -0
  63. package/src/lib/agentic/deployments.d.ts +61 -0
  64. package/src/lib/agentic/deployments.js +203 -0
  65. package/src/lib/agentic/errors.d.ts +65 -0
  66. package/src/lib/agentic/errors.js +84 -0
  67. package/src/lib/agentic/execution/guards.d.ts +9 -0
  68. package/src/lib/agentic/execution/guards.js +30 -0
  69. package/src/lib/agentic/execution/outbound.d.ts +55 -0
  70. package/src/lib/agentic/execution/outbound.js +187 -0
  71. package/src/lib/agentic/execution/send.d.ts +9 -0
  72. package/src/lib/agentic/execution/send.js +268 -0
  73. package/src/lib/agentic/execution/svm-instruction.d.ts +24 -0
  74. package/src/lib/agentic/execution/svm-instruction.js +40 -0
  75. package/src/lib/agentic/execution/svm-outbound.d.ts +18 -0
  76. package/src/lib/agentic/execution/svm-outbound.js +86 -0
  77. package/src/lib/agentic/execution/svm-payload.d.ts +18 -0
  78. package/src/lib/agentic/execution/svm-payload.js +136 -0
  79. package/src/lib/agentic/execution/svm-public.d.ts +5 -0
  80. package/src/lib/agentic/execution/svm-public.js +176 -0
  81. package/src/lib/agentic/execution/svm-quote.d.ts +11 -0
  82. package/src/lib/agentic/execution/svm-quote.js +24 -0
  83. package/src/lib/agentic/execution/svm-send.d.ts +44 -0
  84. package/src/lib/agentic/execution/svm-send.js +87 -0
  85. package/src/lib/agentic/index.d.ts +5 -0
  86. package/src/lib/agentic/index.js +10 -0
  87. package/src/lib/agentic/management/common.d.ts +29 -0
  88. package/src/lib/agentic/management/common.js +116 -0
  89. package/src/lib/agentic/management/create.d.ts +4 -0
  90. package/src/lib/agentic/management/create.js +138 -0
  91. package/src/lib/agentic/management/duplicates.d.ts +4 -0
  92. package/src/lib/agentic/management/duplicates.js +20 -0
  93. package/src/lib/agentic/management/label.d.ts +3 -0
  94. package/src/lib/agentic/management/label.js +17 -0
  95. package/src/lib/agentic/management/prepare.d.ts +7 -0
  96. package/src/lib/agentic/management/prepare.js +95 -0
  97. package/src/lib/agentic/management/rules-write.d.ts +42 -0
  98. package/src/lib/agentic/management/rules-write.js +279 -0
  99. package/src/lib/agentic/management/svm-context.d.ts +25 -0
  100. package/src/lib/agentic/management/svm-context.js +55 -0
  101. package/src/lib/agentic/management/svm-metadata.d.ts +10 -0
  102. package/src/lib/agentic/management/svm-metadata.js +56 -0
  103. package/src/lib/agentic/management/svm-public.d.ts +6 -0
  104. package/src/lib/agentic/management/svm-public.js +125 -0
  105. package/src/lib/agentic/management/svm.d.ts +27 -0
  106. package/src/lib/agentic/management/svm.js +150 -0
  107. package/src/lib/agentic/presets/catalog.d.ts +26 -0
  108. package/src/lib/agentic/presets/catalog.js +307 -0
  109. package/src/lib/agentic/presets/index.d.ts +5 -0
  110. package/src/lib/agentic/presets/index.js +265 -0
  111. package/src/lib/agentic/presets/types.d.ts +48 -0
  112. package/src/lib/agentic/presets/types.js +3 -0
  113. package/src/lib/agentic/public-rule.d.ts +9 -0
  114. package/src/lib/agentic/public-rule.js +326 -0
  115. package/src/lib/agentic/reads/checkpoints.d.ts +17 -0
  116. package/src/lib/agentic/reads/checkpoints.js +109 -0
  117. package/src/lib/agentic/reads/rules.d.ts +42 -0
  118. package/src/lib/agentic/reads/rules.js +302 -0
  119. package/src/lib/agentic/reads/snapshot.d.ts +28 -0
  120. package/src/lib/agentic/reads/snapshot.js +85 -0
  121. package/src/lib/agentic/reads/svm.d.ts +17 -0
  122. package/src/lib/agentic/reads/svm.js +52 -0
  123. package/src/lib/agentic/reads/wallets.d.ts +25 -0
  124. package/src/lib/agentic/reads/wallets.js +122 -0
  125. package/src/lib/agentic/response.d.ts +41 -0
  126. package/src/lib/agentic/response.js +358 -0
  127. package/src/lib/agentic/revert.d.ts +7 -0
  128. package/src/lib/agentic/revert.js +102 -0
  129. package/src/lib/agentic/runtime.d.ts +58 -0
  130. package/src/lib/agentic/runtime.js +104 -0
  131. package/src/lib/agentic/utils.d.ts +57 -0
  132. package/src/lib/agentic/utils.js +165 -0
  133. package/src/lib/agentic/wallet.d.ts +32 -0
  134. package/src/lib/agentic/wallet.js +130 -0
  135. package/src/lib/constants/enums.d.ts +6 -3
  136. package/src/lib/constants/enums.js +6 -3
  137. package/src/lib/constants/index.d.ts +61 -4
  138. package/src/lib/constants/index.js +17 -3
  139. package/src/lib/constants/read-state.d.ts +9 -0
  140. package/src/lib/constants/read-state.js +13 -1
  141. package/src/lib/index.d.ts +8 -2
  142. package/src/lib/index.js +9 -1
  143. package/src/lib/orchestrator/internals/errors.d.ts +7 -0
  144. package/src/lib/orchestrator/internals/errors.js +13 -1
  145. package/src/lib/orchestrator/internals/execute-standard.d.ts +3 -1
  146. package/src/lib/orchestrator/internals/execute-standard.js +3 -3
  147. package/src/lib/orchestrator/internals/outbound-sync.js +52 -7
  148. package/src/lib/orchestrator/internals/push-chain-tx.d.ts +1 -1
  149. package/src/lib/orchestrator/internals/push-chain-tx.js +13 -1
  150. package/src/lib/orchestrator/orchestrator.d.ts +3 -0
  151. package/src/lib/orchestrator/orchestrator.js +13 -1
  152. package/src/lib/orchestrator/orchestrator.types.d.ts +8 -0
  153. package/src/lib/orchestrator/route-detector.js +3 -2
  154. package/src/lib/orchestrator/svm-idl/resolve.d.ts +2 -0
  155. package/src/lib/orchestrator/svm-idl/resolve.js +11 -1
  156. package/src/lib/progress-hook/progress-hook.js +63 -0
  157. package/src/lib/progress-hook/progress-hook.types.d.ts +10 -1
  158. package/src/lib/progress-hook/progress-hook.types.js +10 -0
  159. package/src/lib/push-chain/push-chain.d.ts +57 -15
  160. package/src/lib/push-chain/push-chain.js +66 -7
  161. package/src/lib/read-state/destination.js +6 -1
  162. package/src/lib/read-state/read-params.d.ts +3 -3
  163. package/src/lib/read-state/read-params.js +3 -2
  164. package/src/lib/read-state/read-state.types.d.ts +3 -1
  165. package/src/lib/read-state/read-tracker.js +2 -2
  166. package/src/lib/read-state/spec-builder.js +1 -1
  167. package/src/lib/universal/prc20-address.d.ts +15 -0
  168. package/src/lib/universal/prc20-address.js +135 -0
  169. package/src/lib/utils.d.ts +6 -13
  170. package/src/lib/utils.js +5 -128
  171. package/src/lib/vm-client/evm-client.js +34 -20
@@ -0,0 +1,58 @@
1
+ import { type Address } from 'viem';
2
+ import { CHAIN, PUSH_NETWORK } from '../constants/enums';
3
+ import type { MoveableToken } from '../constants/tokens';
4
+ import type { Orchestrator } from '../orchestrator/orchestrator';
5
+ import type { ExecuteParams, TransactionExecutionOptions, UniversalExecuteParams, UniversalTxResponse } from '../orchestrator/orchestrator.types';
6
+ import type { ProgressEvent } from '../progress-hook/progress-hook.types';
7
+ import { type ChainReader } from './contracts/reader';
8
+ import type { SvmMetadataProvider } from './management/svm-context';
9
+ import type { AgenticProgressHook } from './agentic.types';
10
+ /**
11
+ * Everything the AGW module needs from the surrounding client. Tests supply a
12
+ * mock; PushChain builds the real one from its orchestrator. Keeping this
13
+ * explicit is what separates the signer's identity (gas, account status,
14
+ * ownership derivation) from the AGW execution account.
15
+ */
16
+ export interface AgenticRuntime {
17
+ readonly network: PUSH_NETWORK;
18
+ /** 'eip155:<id>' of the connected Push chain — the native rule chain. */
19
+ readonly pushChainNamespace: string;
20
+ readonly reader: ChainReader;
21
+ readonly isReadOnly: boolean;
22
+ readonly svmMetadata?: SvmMetadataProvider;
23
+ /** Connected signer's Push identity: its EOA, or its UEA for its actual origin chain. */
24
+ signerPushAccount(): Address;
25
+ /** Connected signer's origin account (universal.origin). */
26
+ signerOrigin(): {
27
+ chain: CHAIN;
28
+ address: string;
29
+ };
30
+ signerIsPushNative(): boolean;
31
+ /** The signer's ordinary transaction path (orchestrator.execute). */
32
+ execute(params: ExecuteParams | UniversalExecuteParams, options?: TransactionExecutionOptions): Promise<UniversalTxResponse>;
33
+ /** Sender-preserving UEA/7702 transport; native sequential fallback is forbidden. */
34
+ executeAtomicBatch(params: ExecuteParams, options?: TransactionExecutionOptions): Promise<UniversalTxResponse>;
35
+ /** Emit to the init-time hook and, if different, the per-call hook. */
36
+ emit(event: ProgressEvent, perCallHook?: AgenticProgressHook): void;
37
+ /** Whether the signer's own UEA is deployed (always true for a Push EOA). */
38
+ signerAccountDeployed(): Promise<boolean>;
39
+ signerBalance(): Promise<bigint>;
40
+ getGasPrice(): Promise<bigint>;
41
+ quoteOutbound(prc20: Address, gasLimit: bigint, chain: CHAIN, svm?: {
42
+ wallet: Address;
43
+ splMintBase58?: string;
44
+ burnAmount: bigint;
45
+ }): Promise<{
46
+ protocolFee: bigint;
47
+ nativeValueForGas: bigint;
48
+ gasLimitUsed: bigint;
49
+ }>;
50
+ resolveCEA(account: Address, chain: CHAIN): Promise<{
51
+ cea: Address;
52
+ isDeployed: boolean;
53
+ }>;
54
+ resolvePrc20(token: MoveableToken | string | undefined, chain: CHAIN): Address;
55
+ nowSeconds(): number;
56
+ }
57
+ /** Build the runtime over an orchestrator (the orchestrator IS the internal ctx). */
58
+ export declare function createAgenticRuntime(orchestrator: Orchestrator, isReadOnly: boolean): AgenticRuntime;
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAgenticRuntime = createAgenticRuntime;
4
+ const viem_1 = require("viem");
5
+ const enums_1 = require("../constants/enums");
6
+ const errors_1 = require("../orchestrator/internals/errors");
7
+ const errors_2 = require("./errors");
8
+ const cea_utils_1 = require("../orchestrator/cea-utils");
9
+ const uea_manager_1 = require("../orchestrator/internals/uea-manager");
10
+ const svm_rent_1 = require("../orchestrator/internals/svm-rent");
11
+ const gas_calculator_1 = require("../orchestrator/internals/gas-calculator");
12
+ const helpers_1 = require("../orchestrator/internals/helpers");
13
+ const chain_1 = require("./chain");
14
+ const prc20_address_1 = require("../universal/prc20-address");
15
+ const reader_1 = require("./contracts/reader");
16
+ const svm_metadata_1 = require("./management/svm-metadata");
17
+ const chain_2 = require("../constants/chain");
18
+ /** Build the runtime over an orchestrator (the orchestrator IS the internal ctx). */
19
+ function createAgenticRuntime(orchestrator, isReadOnly) {
20
+ const ctx = orchestrator;
21
+ const network = orchestrator.getNetwork();
22
+ return {
23
+ network,
24
+ pushChainNamespace: (0, chain_1.pushChainNamespaceFor)(network),
25
+ get reader() {
26
+ return (0, reader_1.chainReaderFromPublicClient)(ctx.pushClient.publicClient);
27
+ },
28
+ isReadOnly,
29
+ svmMetadata: (0, svm_metadata_1.createSvmMetadataProvider)({
30
+ [enums_1.CHAIN.SOLANA_DEVNET]: {
31
+ gatewayProgram: chain_2.CHAIN_INFO[enums_1.CHAIN.SOLANA_DEVNET].lockerContract ?? '',
32
+ rpcUrls: orchestrator.getRpcUrls()[enums_1.CHAIN.SOLANA_DEVNET] ??
33
+ chain_2.CHAIN_INFO[enums_1.CHAIN.SOLANA_DEVNET].defaultRPC,
34
+ },
35
+ }),
36
+ signerPushAccount: () => (0, viem_1.getAddress)((0, uea_manager_1.computeUEAOffchain)(ctx)),
37
+ signerOrigin: () => orchestrator.getUOA(),
38
+ signerIsPushNative: () => (0, helpers_1.isPushChain)(ctx.universalSigner.account.chain),
39
+ execute: (params, options) => orchestrator.execute(params, options),
40
+ executeAtomicBatch: async (params, options) => {
41
+ try {
42
+ return await orchestrator.executeAtomicBatch(params, options);
43
+ }
44
+ catch (error) {
45
+ if (error instanceof errors_1.AtomicBatchUnavailableError) {
46
+ throw (0, errors_2.capabilityUnavailable)('atomicNativeAgentBatch', error.message);
47
+ }
48
+ throw error;
49
+ }
50
+ },
51
+ emit: (event, perCallHook) => {
52
+ const base = orchestrator.getProgressHook();
53
+ base?.(event);
54
+ if (perCallHook && perCallHook !== base)
55
+ perCallHook(event);
56
+ },
57
+ signerAccountDeployed: async () => {
58
+ if ((0, helpers_1.isPushChain)(ctx.universalSigner.account.chain))
59
+ return true;
60
+ const status = await orchestrator.getAccountStatus();
61
+ return status.uea.deployed;
62
+ },
63
+ signerBalance: () => ctx.pushClient.getBalance((0, uea_manager_1.computeUEAOffchain)(ctx)),
64
+ getGasPrice: () => ctx.pushClient.getGasPrice(),
65
+ quoteOutbound: async (prc20, gasLimit, chain, svm) => {
66
+ let q = await (0, gas_calculator_1.queryOutboundGasFee)(ctx, prc20, gasLimit, chain);
67
+ if (svm) {
68
+ q = await (0, svm_rent_1.ensureSvmFinalizeGasBudgetQuote)({
69
+ ctx,
70
+ ueaAddress: svm.wallet,
71
+ targetChain: chain,
72
+ prc20Token: prc20,
73
+ quote: q,
74
+ splMintBase58: svm.splMintBase58,
75
+ burnAmount: svm.burnAmount,
76
+ pathTag: 'AGW_SVM',
77
+ });
78
+ }
79
+ return {
80
+ protocolFee: q.protocolFee,
81
+ nativeValueForGas: q.nativeValueForGas,
82
+ gasLimitUsed: q.gasLimitUsed,
83
+ };
84
+ },
85
+ resolveCEA: async (account, chain) => {
86
+ const r = await (0, cea_utils_1.getCEAAddress)(account, chain, orchestrator.getRpcUrls()[chain]?.[0]);
87
+ return { cea: (0, viem_1.getAddress)(r.cea), isDeployed: r.isDeployed };
88
+ },
89
+ resolvePrc20: (token, chain) => {
90
+ if (!token)
91
+ return (0, viem_1.getAddress)((0, helpers_1.getNativePRC20ForChain)(chain, network));
92
+ // Native ETH shares a symbol/address across chains. A plain token must
93
+ // resolve within the known destination, never the first global match.
94
+ if (typeof token === 'object' && 'prc20Address' in token) {
95
+ if (!('sourceChain' in token) || token.sourceChain !== chain)
96
+ throw new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.ASSET_CHAIN_MISMATCH, 'Push token source chain must match the destination chain');
97
+ return (0, viem_1.getAddress)((0, prc20_address_1.getPRC20Address)(token, { network }).address);
98
+ }
99
+ return (0, viem_1.getAddress)((0, prc20_address_1.getPRC20Address)({ chain, address: typeof token === 'string' ? token : token.address }, { network }).address);
100
+ },
101
+ nowSeconds: () => Math.floor(Date.now() / 1000),
102
+ };
103
+ }
104
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1,57 @@
1
+ import { type Address, type Hex } from 'viem';
2
+ import { PUSH_NETWORK } from '../constants/enums';
3
+ import type { AgenticHex, InternalRule, Selector, DecodedSolanaRule } from './agentic.types';
4
+ import type { UniversalRule } from './agentic.types';
5
+ import type { ResolvedUniversalRule } from './codec/universal';
6
+ /**
7
+ * Internal generation context. Harsh H4.1 (October 4): deployment inputs
8
+ * are implementation details, not public helper parameters.
9
+ */
10
+ export interface RulesEncodeContext {
11
+ /** Connected Push network, or an explicit 'eip155:<id>' native chain. */
12
+ network?: PUSH_NETWORK;
13
+ pushChainNamespace?: string;
14
+ validator: Address;
15
+ rulesPolicy: Address;
16
+ gateway?: Address;
17
+ universal?: ReadonlyMap<UniversalRule, ResolvedUniversalRule>;
18
+ /** Wallet owner, for the AGENT_IS_OWNER check. */
19
+ owner?: Address;
20
+ /** Defaults to the current time. */
21
+ nowSeconds?: number;
22
+ }
23
+ /** Internal codecs and identities — not exported from the package entry point. */
24
+ export declare const internalAgenticUtils: {
25
+ /** The ID a grant with this grantNonce produces. Chain is not part of the hash. */
26
+ rulesId(agent: Address, grantNonce: bigint | number, ctx: {
27
+ validator: Address;
28
+ }): AgenticHex;
29
+ /** Hash of one allowed call: keccak256(target ‖ selector). */
30
+ actionId(target: Address, selector: Selector | "value-only"): AgenticHex;
31
+ /** Key of one allowed call's stored config under one rule on one wallet. */
32
+ configId(wallet: Address, rulesId: Hex, actionId: Hex): AgenticHex;
33
+ /** Any-owner wallet address. */
34
+ deriveWallet(owner: Address, index: bigint | number, ctx: {
35
+ factory: Address;
36
+ walletImplementation: Address;
37
+ }): Address;
38
+ /**
39
+ * Encode rules into the grant `Session` bytes, one per rule, in order.
40
+ * EVM universal rules require wallet/token resolution in the internal context.
41
+ */
42
+ encodeRules(rules: readonly InternalRule[], ctx: RulesEncodeContext): AgenticHex[];
43
+ /** Inverse of encodeRules for one Session encoding. */
44
+ decodeRules(bytes: Hex, ctx?: {
45
+ network?: PUSH_NETWORK;
46
+ pushChainNamespace?: string;
47
+ }): InternalRule | DecodedSolanaRule;
48
+ };
49
+ /** Public helpers requiring no contract deployment context. */
50
+ export declare const agenticUtils: {
51
+ actionId: (target: Address, selector: Selector | "value-only") => AgenticHex;
52
+ configId: (wallet: Address, rulesId: Hex, actionId: Hex) => AgenticHex;
53
+ decodeRules: (bytes: Hex, ctx?: {
54
+ network?: PUSH_NETWORK;
55
+ pushChainNamespace?: string;
56
+ }) => InternalRule | DecodedSolanaRule;
57
+ };
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.agenticUtils = exports.internalAgenticUtils = void 0;
4
+ const svm_terms_1 = require("./codec/svm-terms");
5
+ const svm_accounts_1 = require("./codec/svm-accounts");
6
+ const viem_1 = require("viem");
7
+ const enums_1 = require("../constants/enums");
8
+ const tokens_1 = require("../constants/tokens");
9
+ const prc20_address_1 = require("../universal/prc20-address");
10
+ const capabilities_1 = require("./capabilities");
11
+ const deployments_1 = require("./deployments");
12
+ const ids_1 = require("./codec/ids");
13
+ const native_1 = require("./codec/native");
14
+ const rules_1 = require("./codec/rules");
15
+ const selectors_1 = require("./codec/selectors");
16
+ const session_1 = require("./codec/session");
17
+ const errors_1 = require("./errors");
18
+ const chain_1 = require("./chain");
19
+ const universal_terms_1 = require("./codec/universal-terms");
20
+ const universal_1 = require("./codec/universal");
21
+ function nativeNamespace(ctx) {
22
+ if (ctx.pushChainNamespace)
23
+ return ctx.pushChainNamespace;
24
+ return (0, chain_1.pushChainNamespaceFor)(ctx.network ?? enums_1.PUSH_NETWORK.TESTNET_DONUT);
25
+ }
26
+ /** Internal codecs and identities — not exported from the package entry point. */
27
+ exports.internalAgenticUtils = {
28
+ /** The ID a grant with this grantNonce produces. Chain is not part of the hash. */
29
+ rulesId(agent, grantNonce, ctx) {
30
+ return (0, ids_1.rulesId)({
31
+ validator: (0, viem_1.getAddress)(ctx.validator),
32
+ agent: (0, viem_1.getAddress)(agent),
33
+ grantNonce: BigInt(grantNonce),
34
+ });
35
+ },
36
+ /** Hash of one allowed call: keccak256(target ‖ selector). */
37
+ actionId(target, selector) {
38
+ return (0, ids_1.actionId)((0, viem_1.getAddress)(target), (0, selectors_1.parseSelector)(selector).selector);
39
+ },
40
+ /** Key of one allowed call's stored config under one rule on one wallet. */
41
+ configId(wallet, rulesId, actionId) {
42
+ return (0, ids_1.configId)((0, viem_1.getAddress)(wallet), rulesId, actionId);
43
+ },
44
+ /** Any-owner wallet address. */
45
+ deriveWallet(owner, index, ctx) {
46
+ return (0, ids_1.deriveWallet)({
47
+ factory: (0, viem_1.getAddress)(ctx.factory),
48
+ walletImplementation: (0, viem_1.getAddress)(ctx.walletImplementation),
49
+ owner: (0, viem_1.getAddress)(owner),
50
+ index,
51
+ });
52
+ },
53
+ /**
54
+ * Encode rules into the grant `Session` bytes, one per rule, in order.
55
+ * EVM universal rules require wallet/token resolution in the internal context.
56
+ */
57
+ encodeRules(rules, ctx) {
58
+ return (0, rules_1.prepareRules)(rules, {
59
+ owner: ctx.owner ? (0, viem_1.getAddress)(ctx.owner) : undefined,
60
+ pushChainNamespace: nativeNamespace(ctx),
61
+ validator: (0, viem_1.getAddress)(ctx.validator),
62
+ rulesPolicy: (0, viem_1.getAddress)(ctx.rulesPolicy),
63
+ gateway: ctx.gateway,
64
+ universal: ctx.universal,
65
+ capabilities: deployments_1.V6_CAPABILITIES,
66
+ nowSeconds: ctx.nowSeconds ?? Math.floor(Date.now() / 1000),
67
+ }).map((p) => (0, session_1.encodeSession)(p.session));
68
+ },
69
+ /** Inverse of encodeRules for one Session encoding. */
70
+ decodeRules(bytes, ctx = {}) {
71
+ if (!(0, viem_1.isHex)(bytes))
72
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'decodeRules expects hex bytes');
73
+ const session = (0, session_1.decodeSession)(bytes);
74
+ if (session.actions.length === 0 ||
75
+ session.actions.some((a) => a.actionPolicies.length !== 1)) {
76
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.RULE_READ_FAILED, 'every action needs exactly one URP policy to be representable as a public InternalRule');
77
+ }
78
+ const agent = (0, viem_1.getAddress)(`0x${session.sessionValidatorInitData.slice(26, 66)}`);
79
+ const { chainNamespace, body } = (0, session_1.decodeEnvelope)(session.actions[0].actionPolicies[0].initData);
80
+ if (chainNamespace !== nativeNamespace(ctx) &&
81
+ session.actions.length !== 1) {
82
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.RULE_READ_FAILED, 'only native rules carry more than one action');
83
+ }
84
+ if (chainNamespace !== nativeNamespace(ctx)) {
85
+ if (chainNamespace.startsWith('solana:')) {
86
+ const terms = (0, svm_terms_1.decodeSvmTerms)(body);
87
+ (0, svm_terms_1.validateSvmTerms)(terms, -1);
88
+ const assets = terms.assets.map((a) => {
89
+ const chain = chainNamespace;
90
+ const token = (tokens_1.MOVEABLE_TOKENS[chain] ?? []).find((candidate) => {
91
+ try {
92
+ return ((0, viem_1.getAddress)((0, prc20_address_1.getPRC20Address)({ chain, address: candidate.address }, { network: ctx.network ?? enums_1.PUSH_NETWORK.TESTNET_DONUT }).address) === (0, viem_1.getAddress)(a.token));
93
+ }
94
+ catch {
95
+ return false;
96
+ }
97
+ });
98
+ if (!token)
99
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.RULE_READ_FAILED, 'SVM source token is absent from the static registry; use wallet.rules.get()');
100
+ return {
101
+ token: token.mechanism === 'native'
102
+ ? viem_1.zeroAddress
103
+ : (0, svm_accounts_1.svmKey)(token.address),
104
+ maxPerCall: a.maxPerCall,
105
+ maxTotal: a.maxTotal,
106
+ };
107
+ });
108
+ return {
109
+ ...terms,
110
+ format: 'decoded',
111
+ agent,
112
+ chainNamespace: chainNamespace,
113
+ assets,
114
+ };
115
+ }
116
+ if (!chainNamespace.startsWith('eip155:'))
117
+ throw (0, errors_1.capabilityUnavailable)(capabilities_1.AgenticCapability.UNIVERSAL_SVM_RULES, 'unsupported universal chain namespace');
118
+ let terms;
119
+ try {
120
+ terms = (0, universal_terms_1.decodeUniversalTerms)(body);
121
+ }
122
+ catch (cause) {
123
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.RULE_READ_FAILED, 'malformed universal terms', { cause });
124
+ }
125
+ const chain = chainNamespace;
126
+ const network = ctx.network ?? enums_1.PUSH_NETWORK.TESTNET_DONUT;
127
+ const tokens = terms.assets.map((asset) => {
128
+ const token = (tokens_1.MOVEABLE_TOKENS[chain] ?? []).find((candidate) => {
129
+ try {
130
+ return ((0, viem_1.getAddress)((0, prc20_address_1.getPRC20Address)({ chain, address: candidate.address }, { network }).address) === (0, viem_1.getAddress)(asset.token));
131
+ }
132
+ catch {
133
+ return false;
134
+ }
135
+ });
136
+ if (!token)
137
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.RULE_READ_FAILED, `PRC20 ${asset.token} is not in the static ${chain} token registry`, {
138
+ hint: 'Use wallet.rules.get() for on-chain source-token resolution.',
139
+ });
140
+ return token.mechanism === 'native'
141
+ ? viem_1.zeroAddress
142
+ : (0, viem_1.getAddress)(token.address);
143
+ });
144
+ return (0, universal_1.universalTermsToRule)(terms, agent, chainNamespace, tokens);
145
+ }
146
+ // Native: one stored terms body per action, all on the native chain.
147
+ const terms = session.actions.map((a, i) => {
148
+ const env = i === 0
149
+ ? { chainNamespace, body }
150
+ : (0, session_1.decodeEnvelope)(a.actionPolicies[0].initData);
151
+ if (env.chainNamespace !== chainNamespace) {
152
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.RULE_READ_FAILED, `action ${i} names chain ${env.chainNamespace}, not ${chainNamespace}`);
153
+ }
154
+ return (0, native_1.decodeNativeTerms)(env.body);
155
+ });
156
+ return (0, native_1.nativeActionTermsToRule)(terms, agent);
157
+ },
158
+ };
159
+ /** Public helpers requiring no contract deployment context. */
160
+ exports.agenticUtils = {
161
+ actionId: exports.internalAgenticUtils.actionId,
162
+ configId: exports.internalAgenticUtils.configId,
163
+ decodeRules: exports.internalAgenticUtils.decodeRules,
164
+ };
165
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1,32 @@
1
+ import type { AgenticRuntime } from './runtime';
2
+ import type { AgenticAddress, AgenticProgressHook, AgenticWallet, Checkpoint, WalletInfo } from './agentic.types';
3
+ import type { UniversalTxResponse } from '../orchestrator/orchestrator.types';
4
+ /**
5
+ * Management handle for one wallet (spec 1.d). Reads work for any wallet;
6
+ * writes require the connected signer to be the owner. It never sends AS the
7
+ * wallet — that is PushChain.initialize(signer, { agenticWallet }).
8
+ */
9
+ export declare class AgenticWalletHandle implements AgenticWallet {
10
+ private readonly runtime;
11
+ readonly address: AgenticAddress;
12
+ readonly rules: AgenticWallet['rules'];
13
+ private generation?;
14
+ constructor(runtime: AgenticRuntime, address: string);
15
+ /** Deployed wallets resolve their own generation; undeployed ones use the network's current one. */
16
+ private gen;
17
+ info(): Promise<WalletInfo>;
18
+ owner(): Promise<{
19
+ owner: AgenticAddress;
20
+ }>;
21
+ setLabel(label: string, opts?: {
22
+ progressHook?: AgenticProgressHook;
23
+ }): Promise<UniversalTxResponse>;
24
+ checkpoints(opts?: {
25
+ sinceBlock?: bigint;
26
+ }): Promise<{
27
+ checkpoints: Checkpoint[];
28
+ }>;
29
+ private listRules;
30
+ private getRule;
31
+ private signerIdentity;
32
+ }
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AgenticWalletHandle = void 0;
4
+ const public_rule_1 = require("./public-rule");
5
+ const viem_1 = require("viem");
6
+ const capabilities_1 = require("./capabilities");
7
+ const deployments_1 = require("./deployments");
8
+ const errors_1 = require("./errors");
9
+ const rules_write_1 = require("./management/rules-write");
10
+ const checkpoints_1 = require("./reads/checkpoints");
11
+ const rules_1 = require("./reads/rules");
12
+ const snapshot_1 = require("./reads/snapshot");
13
+ const wallets_1 = require("./reads/wallets");
14
+ const deployments_2 = require("./deployments");
15
+ const label_1 = require("./management/label");
16
+ /**
17
+ * Management handle for one wallet (spec 1.d). Reads work for any wallet;
18
+ * writes require the connected signer to be the owner. It never sends AS the
19
+ * wallet — that is PushChain.initialize(signer, { agenticWallet }).
20
+ */
21
+ class AgenticWalletHandle {
22
+ runtime;
23
+ address;
24
+ rules;
25
+ generation;
26
+ constructor(runtime, address) {
27
+ this.runtime = runtime;
28
+ try {
29
+ this.address = (0, viem_1.getAddress)(address);
30
+ }
31
+ catch (cause) {
32
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.NOT_AGENTIC_WALLET, `"${address}" is not an address`, { cause });
33
+ }
34
+ this.rules = {
35
+ list: () => this.listRules(),
36
+ get: (rulesId) => this.getRule(rulesId),
37
+ add: async (rules, opts) => (0, rules_write_1.addRules)(this.runtime, await this.gen(), this.address, (0, public_rule_1.publicRules)(rules), opts?.progressHook),
38
+ update: async (params) => {
39
+ if (!params ||
40
+ !Array.isArray(params.rules) ||
41
+ params.rules.length === 0 ||
42
+ params.rules.some((p) => !p ||
43
+ typeof p.rulesId !== 'string' ||
44
+ !/^0x[0-9a-fA-F]{64}$/.test(p.rulesId))) {
45
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'rules.update needs { rulesId, rule } pairs with 32-byte rule IDs');
46
+ }
47
+ const rules = params.rules.map((p) => ({
48
+ ...p,
49
+ rule: (0, public_rule_1.publicRules)([p.rule])[0],
50
+ }));
51
+ return (0, rules_write_1.updateRules)(this.runtime, await this.gen(), this.address, {
52
+ ...params,
53
+ rules,
54
+ });
55
+ },
56
+ delete: (async (target, opts) => {
57
+ // Validate the target shape before any RPC so a bare revoke costs nothing.
58
+ (0, rules_write_1.assertRevokeTarget)(target);
59
+ return (0, rules_write_1.revokeRules)(this.runtime, await this.gen(), this.address, target, opts?.progressHook);
60
+ }),
61
+ };
62
+ }
63
+ /** Deployed wallets resolve their own generation; undeployed ones use the network's current one. */
64
+ gen() {
65
+ if (!this.generation) {
66
+ this.generation = (0, deployments_1.resolveWalletGeneration)(this.runtime.reader, this.runtime.network, this.address);
67
+ this.generation.catch(() => {
68
+ this.generation = undefined;
69
+ });
70
+ }
71
+ return this.generation;
72
+ }
73
+ async info() {
74
+ let gen;
75
+ try {
76
+ gen = await this.gen();
77
+ }
78
+ catch (err) {
79
+ if (err instanceof errors_1.AgenticError &&
80
+ err.code === errors_1.AGENTIC_ERROR_CODE.WALLET_NOT_DEPLOYED) {
81
+ gen = (0, deployments_2.currentGeneration)(this.runtime.network);
82
+ }
83
+ else {
84
+ throw err;
85
+ }
86
+ }
87
+ (0, capabilities_1.requireCapability)(gen.capabilities, capabilities_1.AgenticCapability.WALLET_READS);
88
+ return (0, wallets_1.walletInfo)(this.runtime.reader, gen, this.address, this.signerIdentity());
89
+ }
90
+ async owner() {
91
+ const gen = await this.gen();
92
+ return {
93
+ owner: (await (0, wallets_1.walletOwner)(this.runtime.reader, gen, this.address)),
94
+ };
95
+ }
96
+ async setLabel(label, opts) {
97
+ (0, label_1.assertLabel)(label);
98
+ return (0, rules_write_1.setLabel)(this.runtime, await this.gen(), this.address, label, opts?.progressHook);
99
+ }
100
+ async checkpoints(opts) {
101
+ const gen = await this.gen();
102
+ const { checkpoints } = await (0, checkpoints_1.readCheckpoints)(this.runtime.reader, gen, this.address, opts?.sinceBlock);
103
+ return { checkpoints };
104
+ }
105
+ async listRules() {
106
+ const gen = await this.gen();
107
+ const snap = await snapshot_1.Snapshot.at(this.runtime.reader);
108
+ return {
109
+ rules: await (0, rules_1.listRules)(snap, gen, this.address, this.runtime.pushChainNamespace),
110
+ };
111
+ }
112
+ async getRule(rulesId) {
113
+ if (typeof rulesId !== 'string' || !/^0x[0-9a-fA-F]{64}$/.test(rulesId)) {
114
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'rulesId must be a 32-byte hex string');
115
+ }
116
+ const gen = await this.gen();
117
+ const snap = await snapshot_1.Snapshot.at(this.runtime.reader);
118
+ return (0, rules_1.getRule)(snap, gen, this.address, rulesId, this.runtime.pushChainNamespace);
119
+ }
120
+ signerIdentity() {
121
+ try {
122
+ return this.runtime.signerPushAccount();
123
+ }
124
+ catch {
125
+ return undefined;
126
+ }
127
+ }
128
+ }
129
+ exports.AgenticWalletHandle = AgenticWalletHandle;
130
+ //# sourceMappingURL=wallet.js.map
@@ -27,11 +27,14 @@ export declare enum CHAIN {
27
27
  SOLANA_DEVNET = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
28
28
  }
29
29
  /**
30
- * Read-only destination exposed with the OG `CHAIN.WEB2` spelling without
31
- * widening the blockchain enum type accepted by transaction APIs.
30
+ * Read-only Web2 source kept on `CHAIN` for compatibility without widening the
31
+ * blockchain enum type accepted by transaction APIs.
32
+ *
33
+ * @deprecated Use `PushChain.CONSTANTS.READ.CHAIN.WEB2`. Same value (`'web2'`);
34
+ * the legacy literal `'web2:https'` is still accepted as read input.
32
35
  */
33
36
  export declare namespace CHAIN {
34
- const WEB2: "web2:https";
37
+ const WEB2: "web2";
35
38
  }
36
39
  /**
37
40
  * Represents the virtual machine or execution environment for a chain.
@@ -35,12 +35,15 @@ var CHAIN;
35
35
  CHAIN["SOLANA_DEVNET"] = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
36
36
  })(CHAIN || (exports.CHAIN = CHAIN = {}));
37
37
  /**
38
- * Read-only destination exposed with the OG `CHAIN.WEB2` spelling without
39
- * widening the blockchain enum type accepted by transaction APIs.
38
+ * Read-only Web2 source kept on `CHAIN` for compatibility without widening the
39
+ * blockchain enum type accepted by transaction APIs.
40
+ *
41
+ * @deprecated Use `PushChain.CONSTANTS.READ.CHAIN.WEB2`. Same value (`'web2'`);
42
+ * the legacy literal `'web2:https'` is still accepted as read input.
40
43
  */
41
44
  // eslint-disable-next-line @typescript-eslint/no-namespace -- declaration merging keeps Web2 out of the transaction enum union
42
45
  (function (CHAIN) {
43
- CHAIN.WEB2 = 'web2:https';
46
+ CHAIN.WEB2 = 'web2';
44
47
  })(CHAIN || (exports.CHAIN = CHAIN = {}));
45
48
  // Namespace properties are normally enumerable after TypeScript emits them.
46
49
  // Keep blockchain enumeration (`Object.values(CHAIN)`) blockchain-only.