@charterlabs/rhinestone-sdk 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +208 -0
- package/dist/accounts/index.d.ts +27 -0
- package/dist/accounts/index.d.ts.map +1 -0
- package/dist/accounts/index.js +289 -0
- package/dist/accounts/nexus.d.ts +20 -0
- package/dist/accounts/nexus.d.ts.map +1 -0
- package/dist/accounts/nexus.js +236 -0
- package/dist/accounts/safe.d.ts +17 -0
- package/dist/accounts/safe.d.ts.map +1 -0
- package/dist/accounts/safe.js +187 -0
- package/dist/accounts/utils.d.ts +27 -0
- package/dist/accounts/utils.d.ts.map +1 -0
- package/dist/accounts/utils.js +181 -0
- package/dist/execution/index.d.ts +33 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +258 -0
- package/dist/execution/smart-session.d.ts +13 -0
- package/dist/execution/smart-session.d.ts.map +1 -0
- package/dist/execution/smart-session.js +85 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +67 -0
- package/dist/modules/abi/smart-sessions.d.ts +42 -0
- package/dist/modules/abi/smart-sessions.d.ts.map +1 -0
- package/dist/modules/abi/smart-sessions.js +131 -0
- package/dist/modules/common.d.ts +16 -0
- package/dist/modules/common.d.ts.map +1 -0
- package/dist/modules/common.js +11 -0
- package/dist/modules/index.d.ts +33 -0
- package/dist/modules/index.d.ts.map +1 -0
- package/dist/modules/index.js +153 -0
- package/dist/modules/omni-account.d.ts +9 -0
- package/dist/modules/omni-account.d.ts.map +1 -0
- package/dist/modules/omni-account.js +15 -0
- package/dist/modules/validators/core.d.ts +23 -0
- package/dist/modules/validators/core.d.ts.map +1 -0
- package/dist/modules/validators/core.js +118 -0
- package/dist/modules/validators/index.d.ts +4 -0
- package/dist/modules/validators/index.d.ts.map +1 -0
- package/dist/modules/validators/index.js +17 -0
- package/dist/modules/validators/smart-sessions.d.ts +29 -0
- package/dist/modules/validators/smart-sessions.d.ts.map +1 -0
- package/dist/modules/validators/smart-sessions.js +426 -0
- package/dist/orchestrator/client.d.ts +29 -0
- package/dist/orchestrator/client.d.ts.map +1 -0
- package/dist/orchestrator/client.js +250 -0
- package/dist/orchestrator/consts.d.ts +5 -0
- package/dist/orchestrator/consts.d.ts.map +1 -0
- package/dist/orchestrator/consts.js +9 -0
- package/dist/orchestrator/error.d.ts +18 -0
- package/dist/orchestrator/error.d.ts.map +1 -0
- package/dist/orchestrator/error.js +33 -0
- package/dist/orchestrator/index.d.ts +11 -0
- package/dist/orchestrator/index.d.ts.map +1 -0
- package/dist/orchestrator/index.js +40 -0
- package/dist/orchestrator/registry.d.ts +17 -0
- package/dist/orchestrator/registry.d.ts.map +1 -0
- package/dist/orchestrator/registry.js +358 -0
- package/dist/orchestrator/types.d.ts +221 -0
- package/dist/orchestrator/types.d.ts.map +1 -0
- package/dist/orchestrator/types.js +19 -0
- package/dist/orchestrator/utils.d.ts +29 -0
- package/dist/orchestrator/utils.d.ts.map +1 -0
- package/dist/orchestrator/utils.js +316 -0
- package/dist/types.d.ts +113 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/package.json +54 -0
package/README.md
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# Rhinestone SDK
|
|
2
|
+
|
|
3
|
+
End-to-end chain abstraction and modularity toolkit
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
### Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install viem @rhinestone/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm install viem @rhinestone/sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
yarn add viem @rhinestone/sdk
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
bun install viem @rhinestone/sdk
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quickstart
|
|
26
|
+
|
|
27
|
+
You'll need a Rhinestone API key, as well as an existing account with some testnet ETH on the source chain.
|
|
28
|
+
|
|
29
|
+
### Creating a Wallet
|
|
30
|
+
|
|
31
|
+
Let's create a smart account with a single owner:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { createRhinestoneAccount } from '@rhinestone/sdk'
|
|
35
|
+
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'
|
|
36
|
+
import { baseSepolia, arbitrumSepolia, optimismSepolia } from 'viem/chains'
|
|
37
|
+
import {
|
|
38
|
+
Chain,
|
|
39
|
+
createPublicClient,
|
|
40
|
+
createWalletClient,
|
|
41
|
+
encodeFunctionData,
|
|
42
|
+
erc20Abi,
|
|
43
|
+
Hex,
|
|
44
|
+
http,
|
|
45
|
+
parseEther,
|
|
46
|
+
} from 'viem'
|
|
47
|
+
|
|
48
|
+
const fundingPrivateKey = process.env.FUNDING_PRIVATE_KEY
|
|
49
|
+
if (!fundingPrivateKey) {
|
|
50
|
+
throw new Error('FUNDING_PRIVATE_KEY is not set')
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const rhinestoneApiKey = process.env.RHINESTONE_API_KEY
|
|
54
|
+
if (!rhinestoneApiKey) {
|
|
55
|
+
throw new Error('RHINESTONE_API_KEY is not set')
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const sourceChain = baseSepolia
|
|
59
|
+
const targetChain = arbitrumSepolia
|
|
60
|
+
|
|
61
|
+
// You can use an existing PK here
|
|
62
|
+
const privateKey = generatePrivateKey()
|
|
63
|
+
console.log(`Owner private key: ${privateKey}`)
|
|
64
|
+
const account = privateKeyToAccount(privateKey)
|
|
65
|
+
|
|
66
|
+
const rhinestoneAccount = await createRhinestoneAccount({
|
|
67
|
+
owners: {
|
|
68
|
+
type: 'ecdsa',
|
|
69
|
+
accounts: [account],
|
|
70
|
+
}
|
|
71
|
+
rhinestoneApiKey,
|
|
72
|
+
})
|
|
73
|
+
const address = await rhinestoneAccount.getAddress()
|
|
74
|
+
console.log(`Smart account address: ${address}`)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Funding the Account
|
|
78
|
+
|
|
79
|
+
We will send some ETH from the funding account to the created smart account. The Orchestrator will use some of that ETH to deploy the account on the target chain, as well as to convert it to USDC for a transfer transaction.
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
const publicClient = createPublicClient({
|
|
83
|
+
chain: sourceChain,
|
|
84
|
+
transport: http(),
|
|
85
|
+
});
|
|
86
|
+
const fundingAccount = privateKeyToAccount(fundingPrivateKey as Hex);
|
|
87
|
+
const fundingClient = createWalletClient({
|
|
88
|
+
account: fundingAccount,
|
|
89
|
+
chain: sourceChain,
|
|
90
|
+
transport: http(),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const txHash = await fundingClient.sendTransaction({
|
|
94
|
+
to: address,
|
|
95
|
+
value: parseEther('0.001'),
|
|
96
|
+
});
|
|
97
|
+
await publicClient.waitForTransactionReceipt({ hash: txHash });
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Sending a Cross-chain Transaction
|
|
101
|
+
|
|
102
|
+
Finally, let's make a cross-chain token transfer:
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
const usdcTarget = '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d';
|
|
106
|
+
const usdcAmount = 1n;
|
|
107
|
+
|
|
108
|
+
const transaction = await rhinestoneAccount.sendTransaction({
|
|
109
|
+
sourceChain,
|
|
110
|
+
targetChain,
|
|
111
|
+
calls: [
|
|
112
|
+
{
|
|
113
|
+
to: usdcTarget,
|
|
114
|
+
value: 0n,
|
|
115
|
+
data: encodeFunctionData({
|
|
116
|
+
abi: erc20Abi,
|
|
117
|
+
functionName: 'transfer',
|
|
118
|
+
args: ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', usdcAmount],
|
|
119
|
+
}),
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
tokenRequests: [
|
|
123
|
+
{
|
|
124
|
+
address: usdcTarget,
|
|
125
|
+
amount: usdcAmount,
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
});
|
|
129
|
+
console.log('Transaction', transaction);
|
|
130
|
+
|
|
131
|
+
const transactionResult = await rhinestoneAccount.waitForExecution(transaction);
|
|
132
|
+
console.log('Result', transactionResult);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
After running that, you will get a smart account deployed on both Base Sepolia and Arbitrum Sepolia, and make a cross-chain USDC transfer.
|
|
136
|
+
|
|
137
|
+
### Using Smart Sessions
|
|
138
|
+
|
|
139
|
+
First, define a session you want to use:
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
const session: Session = {
|
|
143
|
+
owners: {
|
|
144
|
+
type: 'ecdsa',
|
|
145
|
+
accounts: [sessionOwner],
|
|
146
|
+
},
|
|
147
|
+
actions: [
|
|
148
|
+
{
|
|
149
|
+
target: wethAddress,
|
|
150
|
+
selector: toFunctionSelector(
|
|
151
|
+
getAbiItem({
|
|
152
|
+
abi: wethAbi,
|
|
153
|
+
name: 'deposit',
|
|
154
|
+
}),
|
|
155
|
+
),
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
target: wethAddress,
|
|
159
|
+
selector: toFunctionSelector(
|
|
160
|
+
getAbiItem({
|
|
161
|
+
abi: wethAbi,
|
|
162
|
+
name: 'transfer',
|
|
163
|
+
}),
|
|
164
|
+
),
|
|
165
|
+
policies: [
|
|
166
|
+
{
|
|
167
|
+
type: 'universal-action',
|
|
168
|
+
rules: [
|
|
169
|
+
{
|
|
170
|
+
condition: 'equal',
|
|
171
|
+
calldataOffset: 0n,
|
|
172
|
+
referenceValue: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
},
|
|
176
|
+
],
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
During account initialization, provide the session you've just created. Make sure to also provide a bundler configuration.
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
const rhinestoneAccount = await createRhinestoneAccount({
|
|
186
|
+
// …
|
|
187
|
+
sessions: [session],
|
|
188
|
+
bundler: {
|
|
189
|
+
// …
|
|
190
|
+
},
|
|
191
|
+
})
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
When making a transaction, specify the `signers` object to sign it with the session key:
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
const transactionResult = await rhinestoneAccount.sendTransaction({
|
|
198
|
+
// …
|
|
199
|
+
signers: {
|
|
200
|
+
type: 'session',
|
|
201
|
+
session: session,
|
|
202
|
+
},
|
|
203
|
+
})
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Contributing
|
|
207
|
+
|
|
208
|
+
For feature or change requests, feel free to open a PR, start a discussion or get in touch with us.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type Chain, type Hex, type PublicClient } from 'viem';
|
|
2
|
+
import type { OwnerSet, RhinestoneAccountConfig, Session } from '../types';
|
|
3
|
+
declare function getDeployArgs(config: RhinestoneAccountConfig): {
|
|
4
|
+
factory: `0x${string}`;
|
|
5
|
+
factoryData: `0x${string}`;
|
|
6
|
+
salt: `0x${string}`;
|
|
7
|
+
hashedInitcode: `0x${string}`;
|
|
8
|
+
implementation: `0x${string}`;
|
|
9
|
+
initializationCallData: `0x${string}`;
|
|
10
|
+
} | {
|
|
11
|
+
factory: `0x${string}`;
|
|
12
|
+
factoryData: `0x${string}`;
|
|
13
|
+
salt: `0x${string}`;
|
|
14
|
+
hashedInitcode: `0x${string}`;
|
|
15
|
+
implementation: `0x${string}`;
|
|
16
|
+
initializationCallData: null;
|
|
17
|
+
};
|
|
18
|
+
declare function getAddress(config: RhinestoneAccountConfig): `0x${string}`;
|
|
19
|
+
declare function isDeployed(chain: Chain, config: RhinestoneAccountConfig): Promise<boolean>;
|
|
20
|
+
declare function deploySource(chain: Chain, config: RhinestoneAccountConfig): Promise<void>;
|
|
21
|
+
declare function deployTarget(chain: Chain, config: RhinestoneAccountConfig, asUserOp: boolean): Promise<void>;
|
|
22
|
+
declare function getBundleInitCode(config: RhinestoneAccountConfig): `0x${string}` | undefined;
|
|
23
|
+
declare function getSmartAccount(config: RhinestoneAccountConfig, client: PublicClient, chain: Chain): Promise<import("viem/account-abstraction").SmartAccount<import("viem/account-abstraction").SmartAccountImplementation<import("viem").Abi, "0.7">>>;
|
|
24
|
+
declare function getSmartSessionSmartAccount(config: RhinestoneAccountConfig, client: PublicClient, chain: Chain, session: Session): Promise<import("viem/account-abstraction").SmartAccount<import("viem/account-abstraction").SmartAccountImplementation<import("viem").Abi, "0.7">>>;
|
|
25
|
+
declare function sign(validators: OwnerSet, chain: Chain, hash: Hex): Promise<`0x${string}`>;
|
|
26
|
+
export { getDeployArgs, getBundleInitCode, getAddress, isDeployed, deploySource, deployTarget, getSmartAccount, getSmartSessionSmartAccount, sign, };
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../accounts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,KAAK,EAKV,KAAK,GAAG,EAGR,KAAK,YAAY,EAIlB,MAAM,MAAM,CAAA;AAUb,OAAO,KAAK,EAEV,QAAQ,EACR,uBAAuB,EACvB,OAAO,EACR,MAAM,UAAU,CAAA;AAiBjB,iBAAS,aAAa,CAAC,MAAM,EAAE,uBAAuB;;;;;;;;;;;;;;EAUrD;AAED,iBAAS,UAAU,CAAC,MAAM,EAAE,uBAAuB,iBAgBlD;AAED,iBAAe,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,uBAAuB,oBAiBtE;AAED,iBAAe,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,uBAAuB,iBAMxE;AAED,iBAAe,YAAY,CACzB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,uBAAuB,EAC/B,QAAQ,EAAE,OAAO,iBASlB;AAUD,iBAAS,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,6BAUzD;AAgID,iBAAe,eAAe,CAC5B,MAAM,EAAE,uBAAuB,EAC/B,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,KAAK,sJA0Bb;AAED,iBAAe,2BAA2B,CACxC,MAAM,EAAE,uBAAuB,EAC/B,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,OAAO,sJA8BjB;AAED,iBAAe,IAAI,CAAC,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,0BAYhE;AAgED,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,2BAA2B,EAC3B,IAAI,GACL,CAAA"}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDeployArgs = getDeployArgs;
|
|
4
|
+
exports.getBundleInitCode = getBundleInitCode;
|
|
5
|
+
exports.getAddress = getAddress;
|
|
6
|
+
exports.isDeployed = isDeployed;
|
|
7
|
+
exports.deploySource = deploySource;
|
|
8
|
+
exports.deployTarget = deployTarget;
|
|
9
|
+
exports.getSmartAccount = getSmartAccount;
|
|
10
|
+
exports.getSmartSessionSmartAccount = getSmartSessionSmartAccount;
|
|
11
|
+
exports.sign = sign;
|
|
12
|
+
const viem_1 = require("viem");
|
|
13
|
+
const modules_1 = require("../modules");
|
|
14
|
+
const validators_1 = require("../modules/validators");
|
|
15
|
+
const nexus_1 = require("./nexus");
|
|
16
|
+
const safe_1 = require("./safe");
|
|
17
|
+
const utils_1 = require("./utils");
|
|
18
|
+
function getDeployArgs(config) {
|
|
19
|
+
const account = getAccount(config);
|
|
20
|
+
switch (account.type) {
|
|
21
|
+
case 'safe': {
|
|
22
|
+
return (0, safe_1.getDeployArgs)(config);
|
|
23
|
+
}
|
|
24
|
+
case 'nexus': {
|
|
25
|
+
return (0, nexus_1.getDeployArgs)(config);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function getAddress(config) {
|
|
30
|
+
if (is7702(config)) {
|
|
31
|
+
if (!config.eoa) {
|
|
32
|
+
throw new Error('EIP-7702 accounts must have an EOA account');
|
|
33
|
+
}
|
|
34
|
+
return config.eoa.address;
|
|
35
|
+
}
|
|
36
|
+
const { factory, salt, hashedInitcode } = getDeployArgs(config);
|
|
37
|
+
const hash = (0, viem_1.keccak256)((0, viem_1.encodePacked)(['bytes1', 'address', 'bytes32', 'bytes'], ['0xff', factory, salt, hashedInitcode]));
|
|
38
|
+
const address = (0, viem_1.slice)(hash, 12, 32);
|
|
39
|
+
return address;
|
|
40
|
+
}
|
|
41
|
+
async function isDeployed(chain, config) {
|
|
42
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
43
|
+
chain: chain,
|
|
44
|
+
transport: (0, viem_1.http)(),
|
|
45
|
+
});
|
|
46
|
+
const address = getAddress(config);
|
|
47
|
+
const code = await publicClient.getCode({
|
|
48
|
+
address,
|
|
49
|
+
});
|
|
50
|
+
if (!code) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
if (code.startsWith('0xef0100') && code.length === 48) {
|
|
54
|
+
// Defensive check to ensure there's no storage conflict; can be lifted in the future
|
|
55
|
+
throw new Error('Existing EIP-7702 accounts are not yet supported');
|
|
56
|
+
}
|
|
57
|
+
return (0, viem_1.size)(code) > 0;
|
|
58
|
+
}
|
|
59
|
+
async function deploySource(chain, config) {
|
|
60
|
+
if (is7702(config)) {
|
|
61
|
+
return deploy7702Self(chain, config);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
return deployStandalone(chain, config);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async function deployTarget(chain, config, asUserOp) {
|
|
68
|
+
if (is7702(config)) {
|
|
69
|
+
return deploy7702WithBundler(chain, config);
|
|
70
|
+
}
|
|
71
|
+
if (asUserOp) {
|
|
72
|
+
return deployStandalone(chain, config);
|
|
73
|
+
}
|
|
74
|
+
// No need to deploy manually for the intent flow
|
|
75
|
+
}
|
|
76
|
+
async function deployStandalone(chain, config) {
|
|
77
|
+
const deployer = config.deployerAccount;
|
|
78
|
+
if (deployer) {
|
|
79
|
+
return deployStandaloneWithEoa(chain, config, deployer);
|
|
80
|
+
}
|
|
81
|
+
return deployStandaloneWithBundler(chain, config);
|
|
82
|
+
}
|
|
83
|
+
function getBundleInitCode(config) {
|
|
84
|
+
if (is7702(config)) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
const { factory, factoryData } = getDeployArgs(config);
|
|
89
|
+
if (!factory || !factoryData) {
|
|
90
|
+
throw new Error('Factory args not available');
|
|
91
|
+
}
|
|
92
|
+
return (0, viem_1.encodePacked)(['address', 'bytes'], [factory, factoryData]);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async function deploy7702Self(chain, config) {
|
|
96
|
+
if (!config.eoa) {
|
|
97
|
+
throw new Error('EIP-7702 accounts must have an EOA account');
|
|
98
|
+
}
|
|
99
|
+
const account = getAccount(config);
|
|
100
|
+
const { implementation, initializationCallData } = getDeployArgs(config);
|
|
101
|
+
if (!initializationCallData) {
|
|
102
|
+
throw new Error(`Initialization call data not available for ${account.type}`);
|
|
103
|
+
}
|
|
104
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
105
|
+
chain,
|
|
106
|
+
transport: (0, viem_1.http)(),
|
|
107
|
+
});
|
|
108
|
+
const accountClient = (0, viem_1.createWalletClient)({
|
|
109
|
+
account: config.eoa,
|
|
110
|
+
chain,
|
|
111
|
+
transport: (0, viem_1.http)(),
|
|
112
|
+
});
|
|
113
|
+
const authorization = await accountClient.signAuthorization({
|
|
114
|
+
contractAddress: implementation,
|
|
115
|
+
executor: 'self',
|
|
116
|
+
});
|
|
117
|
+
const hash = await accountClient.sendTransaction({
|
|
118
|
+
chain,
|
|
119
|
+
authorizationList: [authorization],
|
|
120
|
+
to: config.eoa.address,
|
|
121
|
+
data: initializationCallData,
|
|
122
|
+
});
|
|
123
|
+
await publicClient.waitForTransactionReceipt({ hash });
|
|
124
|
+
}
|
|
125
|
+
async function deployStandaloneWithEoa(chain, config, deployer) {
|
|
126
|
+
const { factory, factoryData } = getDeployArgs(config);
|
|
127
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
128
|
+
chain: chain,
|
|
129
|
+
transport: (0, viem_1.http)(),
|
|
130
|
+
});
|
|
131
|
+
const client = (0, viem_1.createWalletClient)({
|
|
132
|
+
account: deployer,
|
|
133
|
+
chain: chain,
|
|
134
|
+
transport: (0, viem_1.http)(),
|
|
135
|
+
});
|
|
136
|
+
const tx = await client.sendTransaction({
|
|
137
|
+
to: factory,
|
|
138
|
+
data: factoryData,
|
|
139
|
+
});
|
|
140
|
+
await publicClient.waitForTransactionReceipt({ hash: tx });
|
|
141
|
+
}
|
|
142
|
+
async function deployStandaloneWithBundler(chain, config) {
|
|
143
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
144
|
+
chain,
|
|
145
|
+
transport: (0, viem_1.http)(),
|
|
146
|
+
});
|
|
147
|
+
const bundlerClient = (0, utils_1.getBundlerClient)(config, publicClient);
|
|
148
|
+
const smartAccount = await getSmartAccount(config, publicClient, chain);
|
|
149
|
+
const { factory, factoryData } = getDeployArgs(config);
|
|
150
|
+
const opHash = await bundlerClient.sendUserOperation({
|
|
151
|
+
account: smartAccount,
|
|
152
|
+
factory,
|
|
153
|
+
factoryData,
|
|
154
|
+
calls: [
|
|
155
|
+
{
|
|
156
|
+
to: viem_1.zeroHash,
|
|
157
|
+
value: 0n,
|
|
158
|
+
data: '0x',
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
});
|
|
162
|
+
await bundlerClient.waitForUserOperationReceipt({
|
|
163
|
+
hash: opHash,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
async function deploy7702WithBundler(chain, config) {
|
|
167
|
+
if (!config.eoa) {
|
|
168
|
+
throw new Error('EIP-7702 accounts must have an EOA account');
|
|
169
|
+
}
|
|
170
|
+
const { implementation } = getDeployArgs(config);
|
|
171
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
172
|
+
chain,
|
|
173
|
+
transport: (0, viem_1.http)(),
|
|
174
|
+
});
|
|
175
|
+
const accountClient = (0, viem_1.createWalletClient)({
|
|
176
|
+
account: config.eoa,
|
|
177
|
+
chain,
|
|
178
|
+
transport: (0, viem_1.http)(),
|
|
179
|
+
});
|
|
180
|
+
const bundlerClient = (0, utils_1.getBundlerClient)(config, publicClient);
|
|
181
|
+
const authorization = await accountClient.signAuthorization({
|
|
182
|
+
contractAddress: implementation,
|
|
183
|
+
});
|
|
184
|
+
// Init the account
|
|
185
|
+
const smartAccount = await get7702SmartAccount(config, publicClient);
|
|
186
|
+
const initCalls = await get7702InitCalls(config);
|
|
187
|
+
const opHash = await bundlerClient.sendUserOperation({
|
|
188
|
+
account: smartAccount,
|
|
189
|
+
calls: initCalls,
|
|
190
|
+
authorization,
|
|
191
|
+
});
|
|
192
|
+
await bundlerClient.waitForUserOperationReceipt({
|
|
193
|
+
hash: opHash,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
async function getSmartAccount(config, client, chain) {
|
|
197
|
+
const account = getAccount(config);
|
|
198
|
+
const address = getAddress(config);
|
|
199
|
+
const ownerValidator = (0, validators_1.getOwnerValidator)(config);
|
|
200
|
+
const signFn = (hash) => sign(config.owners, chain, hash);
|
|
201
|
+
switch (account.type) {
|
|
202
|
+
case 'safe': {
|
|
203
|
+
return (0, safe_1.getSmartAccount)(client, address, config.owners, ownerValidator.address, signFn);
|
|
204
|
+
}
|
|
205
|
+
case 'nexus': {
|
|
206
|
+
return (0, nexus_1.getSmartAccount)(client, address, config.owners, ownerValidator.address, signFn);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
async function getSmartSessionSmartAccount(config, client, chain, session) {
|
|
211
|
+
const address = getAddress(config);
|
|
212
|
+
const smartSessionValidator = (0, validators_1.getSmartSessionValidator)(config);
|
|
213
|
+
if (!smartSessionValidator) {
|
|
214
|
+
throw new Error('Smart sessions are not enabled for this account');
|
|
215
|
+
}
|
|
216
|
+
const signFn = (hash) => sign(session.owners, chain, hash);
|
|
217
|
+
const account = getAccount(config);
|
|
218
|
+
switch (account.type) {
|
|
219
|
+
case 'safe': {
|
|
220
|
+
return (0, safe_1.getSessionSmartAccount)(client, address, session, smartSessionValidator.address, signFn);
|
|
221
|
+
}
|
|
222
|
+
case 'nexus': {
|
|
223
|
+
return (0, nexus_1.getSessionSmartAccount)(client, address, session, smartSessionValidator.address, signFn);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async function sign(validators, chain, hash) {
|
|
228
|
+
switch (validators.type) {
|
|
229
|
+
case 'ecdsa': {
|
|
230
|
+
const signatures = await Promise.all(validators.accounts.map((account) => signEcdsa(account, hash)));
|
|
231
|
+
return (0, viem_1.concat)(signatures);
|
|
232
|
+
}
|
|
233
|
+
case 'passkey': {
|
|
234
|
+
return await signPasskey(validators.account, chain, hash);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
async function signEcdsa(account, hash) {
|
|
239
|
+
if (!account.signMessage) {
|
|
240
|
+
throw new Error('Signing not supported for the account');
|
|
241
|
+
}
|
|
242
|
+
return await account.signMessage({ message: { raw: hash } });
|
|
243
|
+
}
|
|
244
|
+
async function signPasskey(account, chain, hash) {
|
|
245
|
+
const { webauthn, signature } = await account.sign({ hash });
|
|
246
|
+
const usePrecompiled = (0, modules_1.isRip7212SupportedNetwork)(chain);
|
|
247
|
+
const encodedSignature = (0, modules_1.getWebauthnValidatorSignature)({
|
|
248
|
+
webauthn,
|
|
249
|
+
signature,
|
|
250
|
+
usePrecompiled,
|
|
251
|
+
});
|
|
252
|
+
return encodedSignature;
|
|
253
|
+
}
|
|
254
|
+
async function get7702SmartAccount(config, client) {
|
|
255
|
+
if (!config.eoa) {
|
|
256
|
+
throw new Error('EIP-7702 accounts must have an EOA account');
|
|
257
|
+
}
|
|
258
|
+
const account = getAccount(config);
|
|
259
|
+
switch (account.type) {
|
|
260
|
+
case 'safe': {
|
|
261
|
+
return (0, safe_1.get7702SmartAccount)();
|
|
262
|
+
}
|
|
263
|
+
case 'nexus': {
|
|
264
|
+
return (0, nexus_1.get7702SmartAccount)(config.eoa, client);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
async function get7702InitCalls(config) {
|
|
269
|
+
const account = getAccount(config);
|
|
270
|
+
switch (account.type) {
|
|
271
|
+
case 'safe': {
|
|
272
|
+
return (0, safe_1.get7702InitCalls)();
|
|
273
|
+
}
|
|
274
|
+
case 'nexus': {
|
|
275
|
+
return (0, nexus_1.get7702InitCalls)(config);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function is7702(config) {
|
|
280
|
+
return config.eoa !== undefined;
|
|
281
|
+
}
|
|
282
|
+
function getAccount(config) {
|
|
283
|
+
if (config.account) {
|
|
284
|
+
return config.account;
|
|
285
|
+
}
|
|
286
|
+
return {
|
|
287
|
+
type: 'nexus',
|
|
288
|
+
};
|
|
289
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Abi, Account, Address, Hex, PublicClient } from 'viem';
|
|
2
|
+
import { type SmartAccount, type SmartAccountImplementation } from 'viem/account-abstraction';
|
|
3
|
+
import type { OwnerSet, RhinestoneAccountConfig, Session } from '../types';
|
|
4
|
+
declare function getDeployArgs(config: RhinestoneAccountConfig): {
|
|
5
|
+
factory: `0x${string}`;
|
|
6
|
+
factoryData: `0x${string}`;
|
|
7
|
+
salt: `0x${string}`;
|
|
8
|
+
hashedInitcode: `0x${string}`;
|
|
9
|
+
implementation: `0x${string}`;
|
|
10
|
+
initializationCallData: `0x${string}`;
|
|
11
|
+
};
|
|
12
|
+
declare function getSmartAccount(client: PublicClient, address: Address, owners: OwnerSet, validatorAddress: Address, sign: (hash: Hex) => Promise<Hex>): Promise<SmartAccount<SmartAccountImplementation<Abi, "0.7">>>;
|
|
13
|
+
declare function getSessionSmartAccount(client: PublicClient, address: Address, session: Session, validatorAddress: Address, sign: (hash: Hex) => Promise<Hex>): Promise<SmartAccount<SmartAccountImplementation<Abi, "0.7">>>;
|
|
14
|
+
declare function get7702SmartAccount(account: Account, client: PublicClient): Promise<SmartAccount<SmartAccountImplementation<Abi, "0.7">>>;
|
|
15
|
+
declare function get7702InitCalls(config: RhinestoneAccountConfig): {
|
|
16
|
+
to: `0x${string}`;
|
|
17
|
+
data: `0x${string}`;
|
|
18
|
+
}[];
|
|
19
|
+
export { getDeployArgs, getSmartAccount, getSessionSmartAccount, get7702SmartAccount, get7702InitCalls, };
|
|
20
|
+
//# sourceMappingURL=nexus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nexus.d.ts","sourceRoot":"","sources":["../../accounts/nexus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAUpE,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,0BAA0B,EAEhC,MAAM,0BAA0B,CAAA;AASjC,OAAO,KAAK,EAAE,QAAQ,EAAE,uBAAuB,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAa1E,iBAAS,aAAa,CAAC,MAAM,EAAE,uBAAuB;;;;;;;EA8ErD;AAED,iBAAe,eAAe,CAC5B,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,QAAQ,EAChB,gBAAgB,EAAE,OAAO,EACzB,IAAI,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,iEAWlC;AAED,iBAAe,sBAAsB,CACnC,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,EAChB,gBAAgB,EAAE,OAAO,EACzB,IAAI,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,iEAuBlC;AAED,iBAAe,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,iEAkBxE;AAgFD,iBAAS,gBAAgB,CAAC,MAAM,EAAE,uBAAuB;;;IAqDxD;AAED,OAAO,EACL,aAAa,EACb,eAAe,EACf,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,GACjB,CAAA"}
|