@rhinestone/sdk 2.0.0-beta.1 → 2.0.0-beta.2

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 (60) hide show
  1. package/README.md +42 -1
  2. package/dist/src/accounts/index.d.ts.map +1 -1
  3. package/dist/src/accounts/index.js +6 -34
  4. package/dist/src/actions/smart-sessions.d.ts.map +1 -1
  5. package/dist/src/actions/smart-sessions.js +3 -3
  6. package/dist/src/execution/index.d.ts +3 -4
  7. package/dist/src/execution/index.d.ts.map +1 -1
  8. package/dist/src/execution/index.js +3 -27
  9. package/dist/src/execution/utils.d.ts +1 -1
  10. package/dist/src/execution/utils.d.ts.map +1 -1
  11. package/dist/src/execution/utils.js +7 -5
  12. package/dist/src/index.d.ts +16 -12
  13. package/dist/src/index.d.ts.map +1 -1
  14. package/dist/src/index.js +9 -39
  15. package/dist/src/modules/index.d.ts +2 -2
  16. package/dist/src/modules/index.d.ts.map +1 -1
  17. package/dist/src/modules/index.js +2 -2
  18. package/dist/src/modules/read.d.ts.map +1 -1
  19. package/dist/src/modules/read.js +2 -4
  20. package/dist/src/modules/validators/index.d.ts +2 -2
  21. package/dist/src/modules/validators/index.d.ts.map +1 -1
  22. package/dist/src/modules/validators/index.js +2 -2
  23. package/dist/src/modules/validators/permissions.d.ts +5 -0
  24. package/dist/src/modules/validators/permissions.d.ts.map +1 -0
  25. package/dist/src/modules/validators/permissions.js +111 -0
  26. package/dist/src/modules/validators/policies/claim/permit2.d.ts +29 -3
  27. package/dist/src/modules/validators/policies/claim/permit2.d.ts.map +1 -1
  28. package/dist/src/modules/validators/smart-sessions.d.ts +14 -27
  29. package/dist/src/modules/validators/smart-sessions.d.ts.map +1 -1
  30. package/dist/src/modules/validators/smart-sessions.js +71 -17
  31. package/dist/src/orchestrator/consts.d.ts +1 -1
  32. package/dist/src/orchestrator/consts.js +1 -1
  33. package/dist/src/orchestrator/index.d.ts +2 -2
  34. package/dist/src/orchestrator/index.d.ts.map +1 -1
  35. package/dist/src/orchestrator/index.js +2 -2
  36. package/dist/src/orchestrator/registry.d.ts +1 -8
  37. package/dist/src/orchestrator/registry.d.ts.map +1 -1
  38. package/dist/src/orchestrator/registry.js +1 -26
  39. package/dist/src/types.d.ts +99 -28
  40. package/dist/src/types.d.ts.map +1 -1
  41. package/dist/src/utils/index.d.ts +2 -1
  42. package/dist/src/utils/index.d.ts.map +1 -1
  43. package/dist/src/utils/index.js +2 -1
  44. package/dist/src/utils/walletClient.d.ts.map +1 -0
  45. package/dist/src/{accounts → utils}/walletClient.js +1 -1
  46. package/package.json +1 -5
  47. package/dist/src/accounts/passport.d.ts +0 -9
  48. package/dist/src/accounts/passport.d.ts.map +0 -1
  49. package/dist/src/accounts/passport.js +0 -78
  50. package/dist/src/accounts/walletClient.d.ts.map +0 -1
  51. package/dist/src/actions/compact.d.ts +0 -15
  52. package/dist/src/actions/compact.d.ts.map +0 -1
  53. package/dist/src/actions/compact.js +0 -200
  54. package/dist/src/actions/deployment.d.ts +0 -19
  55. package/dist/src/actions/deployment.d.ts.map +0 -1
  56. package/dist/src/actions/deployment.js +0 -76
  57. package/dist/src/execution/permit2.d.ts +0 -7
  58. package/dist/src/execution/permit2.d.ts.map +0 -1
  59. package/dist/src/execution/permit2.js +0 -51
  60. /package/dist/src/{accounts → utils}/walletClient.d.ts +0 -0
@@ -1,200 +0,0 @@
1
- import { concat, encodeFunctionData, erc20Abi, zeroAddress, } from 'viem';
2
- import { COMPACT_ADDRESS } from '../execution/compact.js';
3
- const ALLOCATOR_ADDRESS = '0xc7732071e3a1be6cfce6d13bb05699a31a457679';
4
- const DEFAULT_RESET_PERIOD = 6;
5
- const DEFAULT_SCOPE = 0;
6
- function depositEther(value) {
7
- return {
8
- async resolve({ accountAddress }) {
9
- return {
10
- to: COMPACT_ADDRESS,
11
- data: encodeFunctionData({
12
- abi: [
13
- {
14
- type: 'function',
15
- name: 'depositNative',
16
- inputs: [
17
- { name: 'lockTag', type: 'bytes12', internalType: 'bytes12' },
18
- { name: 'recipient', type: 'address', internalType: 'address' },
19
- ],
20
- outputs: [
21
- { name: 'id', type: 'uint256', internalType: 'uint256' },
22
- ],
23
- stateMutability: 'payable',
24
- },
25
- ],
26
- functionName: 'depositNative',
27
- args: [lockTag(), accountAddress],
28
- }),
29
- value,
30
- };
31
- },
32
- };
33
- }
34
- function enableEtherWithdrawal() {
35
- const id = concat([lockTag(), zeroAddress]);
36
- return enableForcedWithdrawal(BigInt(id));
37
- }
38
- function disableEtherWithdrawal() {
39
- const id = concat([lockTag(), zeroAddress]);
40
- return disableForcedWithdrawal(BigInt(id));
41
- }
42
- function withdrawEther(value) {
43
- return {
44
- async resolve({ accountAddress }) {
45
- const id = concat([lockTag(), zeroAddress]);
46
- return forcedWithdrawal(BigInt(id), accountAddress, value);
47
- },
48
- };
49
- }
50
- function depositErc20(tokenAddress, amount) {
51
- return {
52
- async resolve({ accountAddress }) {
53
- return {
54
- to: COMPACT_ADDRESS,
55
- value: 0n,
56
- data: encodeFunctionData({
57
- abi: [
58
- {
59
- type: 'function',
60
- name: 'depositERC20',
61
- inputs: [
62
- { name: 'token', type: 'address', internalType: 'address' },
63
- { name: 'lockTag', type: 'bytes12', internalType: 'bytes12' },
64
- { name: 'amount', type: 'uint256', internalType: 'uint256' },
65
- { name: 'recipient', type: 'address', internalType: 'address' },
66
- ],
67
- outputs: [
68
- { name: 'id', type: 'uint256', internalType: 'uint256' },
69
- ],
70
- stateMutability: 'nonpayable',
71
- },
72
- ],
73
- functionName: 'depositERC20',
74
- args: [tokenAddress, lockTag(), amount, accountAddress],
75
- }),
76
- };
77
- },
78
- };
79
- }
80
- function enableErc20Withdrawal(tokenAddress) {
81
- const id = concat([lockTag(), tokenAddress]);
82
- return enableForcedWithdrawal(BigInt(id));
83
- }
84
- function disableErc20Withdrawal(tokenAddress) {
85
- const id = concat([lockTag(), tokenAddress]);
86
- return disableForcedWithdrawal(BigInt(id));
87
- }
88
- function withdrawErc20(tokenAddress, amount) {
89
- return {
90
- async resolve({ accountAddress }) {
91
- const id = concat([lockTag(), tokenAddress]);
92
- return forcedWithdrawal(BigInt(id), accountAddress, amount);
93
- },
94
- };
95
- }
96
- function enableForcedWithdrawal(id) {
97
- return {
98
- to: COMPACT_ADDRESS,
99
- data: encodeFunctionData({
100
- abi: [
101
- {
102
- type: 'function',
103
- name: 'enableForcedWithdrawal',
104
- inputs: [{ name: 'id', type: 'uint256', internalType: 'uint256' }],
105
- outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
106
- stateMutability: 'nonpayable',
107
- },
108
- ],
109
- functionName: 'enableForcedWithdrawal',
110
- args: [id],
111
- }),
112
- value: 0n,
113
- };
114
- }
115
- function disableForcedWithdrawal(id) {
116
- return {
117
- to: COMPACT_ADDRESS,
118
- data: encodeFunctionData({
119
- abi: [
120
- {
121
- type: 'function',
122
- name: 'disableForcedWithdrawal',
123
- inputs: [{ name: 'id', type: 'uint256', internalType: 'uint256' }],
124
- outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
125
- stateMutability: 'nonpayable',
126
- },
127
- ],
128
- functionName: 'disableForcedWithdrawal',
129
- args: [id],
130
- }),
131
- value: 0n,
132
- };
133
- }
134
- function forcedWithdrawal(id, recipient, amount) {
135
- return {
136
- to: COMPACT_ADDRESS,
137
- data: encodeFunctionData({
138
- abi: [
139
- {
140
- type: 'function',
141
- name: 'forcedWithdrawal',
142
- inputs: [
143
- { name: 'id', type: 'uint256', internalType: 'uint256' },
144
- { name: 'recipient', type: 'address', internalType: 'address' },
145
- { name: 'amount', type: 'uint256', internalType: 'uint256' },
146
- ],
147
- outputs: [{ name: '', type: 'bool', internalType: 'bool' }],
148
- stateMutability: 'nonpayable',
149
- },
150
- ],
151
- functionName: 'forcedWithdrawal',
152
- args: [id, recipient, amount],
153
- }),
154
- value: 0n,
155
- };
156
- }
157
- function approveErc20(tokenAddress, amount) {
158
- return {
159
- to: tokenAddress,
160
- value: 0n,
161
- data: encodeFunctionData({
162
- abi: erc20Abi,
163
- functionName: 'approve',
164
- args: [COMPACT_ADDRESS, amount],
165
- }),
166
- };
167
- }
168
- function toCompactFlag(allocator) {
169
- const addrBytes = Buffer.from(allocator.slice(2), 'hex');
170
- let leadingZeroNibbles = 0;
171
- for (const byte of addrBytes) {
172
- if (byte === 0) {
173
- leadingZeroNibbles += 2;
174
- }
175
- else {
176
- if (byte >> 4 === 0)
177
- leadingZeroNibbles += 1;
178
- break;
179
- }
180
- }
181
- if (leadingZeroNibbles >= 18)
182
- return 15;
183
- if (leadingZeroNibbles >= 4)
184
- return leadingZeroNibbles - 3;
185
- return 0;
186
- }
187
- function usingAllocatorId(allocator = ALLOCATOR_ADDRESS) {
188
- const compactFlag = BigInt(toCompactFlag(allocator));
189
- const last88Bits = BigInt(`0x${allocator.slice(-22)}`); // Extract last 88 bits (11 bytes * 2 hex chars per byte)
190
- return (compactFlag << 88n) | last88Bits;
191
- }
192
- function lockTag() {
193
- const allocatorId = usingAllocatorId(ALLOCATOR_ADDRESS);
194
- const tagBig = (BigInt(DEFAULT_SCOPE) << 255n) |
195
- (BigInt(DEFAULT_RESET_PERIOD) << 252n) |
196
- (allocatorId << 160n);
197
- const hex = tagBig.toString(16).slice(0, 24);
198
- return `0x${hex}`;
199
- }
200
- export { ALLOCATOR_ADDRESS, depositEther, enableEtherWithdrawal, disableEtherWithdrawal, withdrawEther, depositErc20, enableErc20Withdrawal, disableErc20Withdrawal, withdrawErc20, approveErc20, lockTag, };
@@ -1,19 +0,0 @@
1
- import type { Address, Chain } from 'viem';
2
- import type { AccountProviderConfig, RhinestoneSDKConfig } from '../types.js';
3
- /**
4
- * Deploy smart accounts for multiple users from a backend using a sponsor wallet.
5
- * The sponsor pays for gas, but users own and control their accounts.
6
- */
7
- declare function deployAccountsForOwners(params: {
8
- sponsorAccount: import('viem').Account;
9
- ownerAddresses: Address[];
10
- accountConfig: AccountProviderConfig;
11
- chain: Chain;
12
- sdkConfig?: RhinestoneSDKConfig;
13
- sponsored?: boolean;
14
- }): Promise<Array<{
15
- owner: Address;
16
- account: Address;
17
- }>>;
18
- export { deployAccountsForOwners };
19
- //# sourceMappingURL=deployment.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deployment.d.ts","sourceRoot":"","sources":["../../../actions/deployment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAO,MAAM,MAAM,CAAA;AAQ/C,OAAO,KAAK,EACV,qBAAqB,EAErB,mBAAmB,EACpB,MAAM,UAAU,CAAA;AAyCjB;;;GAGG;AACH,iBAAe,uBAAuB,CAAC,MAAM,EAAE;IAC7C,cAAc,EAAE,OAAO,MAAM,EAAE,OAAO,CAAA;IACtC,cAAc,EAAE,OAAO,EAAE,CAAA;IACzB,aAAa,EAAE,qBAAqB,CAAA;IACpC,KAAK,EAAE,KAAK,CAAA;IACZ,SAAS,CAAC,EAAE,mBAAmB,CAAA;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB,GAAG,OAAO,CAAC,KAAK,CAAC;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC,CAmDvD;AAED,OAAO,EAAE,uBAAuB,EAAE,CAAA"}
@@ -1,76 +0,0 @@
1
- import { createPublicClient, createWalletClient } from 'viem';
2
- import { getAddress as getAddressInternal, getInitCode as getInitCodeInternal, isDeployed as isDeployedInternal, } from '../accounts/index.js';
3
- import { createTransport } from '../accounts/utils.js';
4
- async function deployWithCustomFactory(sponsorConfig, chain, factoryArgs) {
5
- const sponsorOwners = sponsorConfig.owners;
6
- if (!sponsorOwners ||
7
- sponsorOwners.type !== 'ecdsa' ||
8
- sponsorOwners.accounts.length === 0) {
9
- throw new Error('Sponsor must have an ECDSA account');
10
- }
11
- const sponsorAccount = sponsorOwners.accounts[0];
12
- if (!('signTransaction' in sponsorAccount)) {
13
- throw new Error('Sponsor account must be able to sign transactions');
14
- }
15
- const publicClient = createPublicClient({
16
- chain,
17
- transport: createTransport(chain, sponsorConfig.provider),
18
- });
19
- const walletClient = createWalletClient({
20
- account: sponsorAccount,
21
- chain,
22
- transport: createTransport(chain, sponsorConfig.provider),
23
- });
24
- const hash = await walletClient.sendTransaction({
25
- to: factoryArgs.factory,
26
- data: factoryArgs.factoryData,
27
- value: 0n,
28
- });
29
- await publicClient.waitForTransactionReceipt({ hash });
30
- }
31
- /**
32
- * Deploy smart accounts for multiple users from a backend using a sponsor wallet.
33
- * The sponsor pays for gas, but users own and control their accounts.
34
- */
35
- async function deployAccountsForOwners(params) {
36
- const { sponsorAccount, ownerAddresses, accountConfig, chain, sdkConfig } = params;
37
- const results = [];
38
- for (const ownerAddress of ownerAddresses) {
39
- const ownerAccountRef = {
40
- address: ownerAddress,
41
- type: 'json-rpc',
42
- };
43
- const userConfig = {
44
- account: accountConfig,
45
- owners: {
46
- type: 'ecdsa',
47
- accounts: [ownerAccountRef],
48
- threshold: 1,
49
- },
50
- ...sdkConfig,
51
- };
52
- const accountAddress = getAddressInternal(userConfig);
53
- const isAlreadyDeployed = await isDeployedInternal(userConfig, chain);
54
- if (isAlreadyDeployed) {
55
- results.push({ owner: ownerAddress, account: accountAddress });
56
- continue;
57
- }
58
- const sponsorConfig = {
59
- account: accountConfig,
60
- owners: {
61
- type: 'ecdsa',
62
- accounts: [sponsorAccount],
63
- threshold: 1,
64
- },
65
- ...sdkConfig,
66
- };
67
- const initCode = getInitCodeInternal(userConfig);
68
- if (!initCode || !('factory' in initCode)) {
69
- throw new Error('Failed to get init code for account deployment');
70
- }
71
- await deployWithCustomFactory(sponsorConfig, chain, initCode);
72
- results.push({ owner: ownerAddress, account: accountAddress });
73
- }
74
- return results;
75
- }
76
- export { deployAccountsForOwners };
@@ -1,7 +0,0 @@
1
- import { type Address, type Chain } from 'viem';
2
- import type { RhinestoneConfig } from '../types.js';
3
- declare function checkERC20AllowanceDirect(owner: Address, spender: Address, tokenAddress: Address, publicClient: any): Promise<bigint>;
4
- declare function checkERC20Allowance(tokenAddress: Address, chain: Chain, config: RhinestoneConfig): Promise<bigint>;
5
- declare function getPermit2Address(): Address;
6
- export { checkERC20Allowance, checkERC20AllowanceDirect, getPermit2Address };
7
- //# sourceMappingURL=permit2.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"permit2.d.ts","sourceRoot":"","sources":["../../../execution/permit2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,KAAK,EAAsB,MAAM,MAAM,CAAA;AAEnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAIhD,iBAAe,yBAAyB,CACtC,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,OAAO,EACrB,YAAY,EAAE,GAAG,GAChB,OAAO,CAAC,MAAM,CAAC,CAyBjB;AAED,iBAAe,mBAAmB,CAChC,YAAY,EAAE,OAAO,EACrB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,MAAM,CAAC,CAuBjB;AAED,iBAAS,iBAAiB,IAAI,OAAO,CAEpC;AAED,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,CAAA"}
@@ -1,51 +0,0 @@
1
- import { createPublicClient } from 'viem';
2
- import { createTransport } from '../accounts/utils.js';
3
- const PERMIT2_ADDRESS = '0x000000000022D473030F116dDEE9F6B43aC78BA3';
4
- async function checkERC20AllowanceDirect(owner, spender, tokenAddress, publicClient) {
5
- try {
6
- const allowance = await publicClient.readContract({
7
- address: tokenAddress,
8
- abi: [
9
- {
10
- name: 'allowance',
11
- type: 'function',
12
- stateMutability: 'view',
13
- inputs: [
14
- { name: 'owner', type: 'address' },
15
- { name: 'spender', type: 'address' },
16
- ],
17
- outputs: [{ name: '', type: 'uint256' }],
18
- },
19
- ],
20
- functionName: 'allowance',
21
- args: [owner, spender],
22
- });
23
- return BigInt(allowance.toString());
24
- }
25
- catch (error) {
26
- console.error('Error checking ERC20 allowance:', error);
27
- throw new Error('Failed to check ERC20 allowance');
28
- }
29
- }
30
- async function checkERC20Allowance(tokenAddress, chain, config) {
31
- try {
32
- const publicClient = createPublicClient({
33
- chain,
34
- transport: createTransport(chain, config.provider),
35
- });
36
- // Get the account owner from the config
37
- const owner = config.eoa?.address;
38
- if (!owner) {
39
- throw new Error('No EOA address found in account config');
40
- }
41
- return await checkERC20AllowanceDirect(owner, PERMIT2_ADDRESS, tokenAddress, publicClient);
42
- }
43
- catch (error) {
44
- console.error('Error checking ERC20 allowance:', error);
45
- throw new Error('Failed to check ERC20 allowance');
46
- }
47
- }
48
- function getPermit2Address() {
49
- return PERMIT2_ADDRESS;
50
- }
51
- export { checkERC20Allowance, checkERC20AllowanceDirect, getPermit2Address };
File without changes