@rhinestone/sdk 2.0.0-beta.29 → 2.0.0-beta.30
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/dist/src/accounts/error.d.ts +1 -15
- package/dist/src/accounts/error.d.ts.map +1 -1
- package/dist/src/accounts/error.js +1 -17
- package/dist/src/accounts/hca.d.ts +1 -2
- package/dist/src/accounts/hca.d.ts.map +1 -1
- package/dist/src/accounts/hca.js +9 -13
- package/dist/src/accounts/index.d.ts +3 -4
- package/dist/src/accounts/index.d.ts.map +1 -1
- package/dist/src/accounts/index.js +8 -41
- package/dist/src/accounts/kernel.d.ts +1 -2
- package/dist/src/accounts/kernel.d.ts.map +1 -1
- package/dist/src/accounts/kernel.js +1 -8
- package/dist/src/accounts/nexus.d.ts +1 -2
- package/dist/src/accounts/nexus.d.ts.map +1 -1
- package/dist/src/accounts/nexus.js +1 -8
- package/dist/src/accounts/safe.d.ts +1 -2
- package/dist/src/accounts/safe.d.ts.map +1 -1
- package/dist/src/accounts/safe.js +3 -9
- package/dist/src/accounts/signing/common.d.ts +1 -4
- package/dist/src/accounts/signing/common.d.ts.map +1 -1
- package/dist/src/accounts/signing/common.js +3 -7
- package/dist/src/accounts/signing/message.d.ts.map +1 -1
- package/dist/src/accounts/signing/message.js +1 -4
- package/dist/src/accounts/signing/typedData.d.ts.map +1 -1
- package/dist/src/accounts/signing/typedData.js +1 -4
- package/dist/src/accounts/startale.d.ts +1 -2
- package/dist/src/accounts/startale.d.ts.map +1 -1
- package/dist/src/accounts/startale.js +2 -5
- package/dist/src/actions/smart-sessions.d.ts +15 -81
- package/dist/src/actions/smart-sessions.d.ts.map +1 -1
- package/dist/src/actions/smart-sessions.js +18 -90
- package/dist/src/errors/index.d.ts +3 -3
- package/dist/src/errors/index.d.ts.map +1 -1
- package/dist/src/errors/index.js +4 -4
- package/dist/src/execution/error.d.ts +1 -15
- package/dist/src/execution/error.d.ts.map +1 -1
- package/dist/src/execution/error.js +1 -17
- package/dist/src/execution/index.d.ts +4 -3
- package/dist/src/execution/index.d.ts.map +1 -1
- package/dist/src/execution/index.js +5 -11
- package/dist/src/execution/utils.d.ts +2 -2
- package/dist/src/execution/utils.d.ts.map +1 -1
- package/dist/src/execution/utils.js +10 -22
- package/dist/src/index.d.ts +5 -13
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +11 -10
- package/dist/src/modules/index.d.ts.map +1 -1
- package/dist/src/modules/index.js +0 -5
- package/dist/src/modules/validators/core.d.ts +3 -4
- package/dist/src/modules/validators/core.d.ts.map +1 -1
- package/dist/src/modules/validators/core.js +20 -31
- package/dist/src/modules/validators/cross-chain-permits.d.ts +11 -0
- package/dist/src/modules/validators/cross-chain-permits.d.ts.map +1 -0
- package/dist/src/modules/validators/cross-chain-permits.js +76 -0
- package/dist/src/modules/validators/permissions.d.ts.map +1 -1
- package/dist/src/modules/validators/permissions.js +2 -3
- package/dist/src/modules/validators/smart-sessions.d.ts +5 -1
- package/dist/src/modules/validators/smart-sessions.d.ts.map +1 -1
- package/dist/src/modules/validators/smart-sessions.js +66 -2
- package/dist/src/orchestrator/client.d.ts.map +1 -1
- package/dist/src/orchestrator/client.js +12 -0
- package/dist/src/orchestrator/consts.d.ts +1 -1
- package/dist/src/orchestrator/consts.js +1 -1
- package/dist/src/orchestrator/index.d.ts +2 -2
- package/dist/src/orchestrator/index.d.ts.map +1 -1
- package/dist/src/orchestrator/types.d.ts +13 -1
- package/dist/src/orchestrator/types.d.ts.map +1 -1
- package/dist/src/smart-sessions/index.d.ts +5 -0
- package/dist/src/smart-sessions/index.d.ts.map +1 -0
- package/dist/src/smart-sessions/index.js +6 -0
- package/dist/src/types.d.ts +81 -26
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +3 -7
- package/dist/src/actions/recovery.d.ts +0 -33
- package/dist/src/actions/recovery.d.ts.map +0 -1
- package/dist/src/actions/recovery.js +0 -189
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { createPublicClient, } from 'viem';
|
|
2
|
-
import { getModuleInstallationCalls } from '../accounts/index.js';
|
|
3
|
-
import { createTransport } from '../accounts/json-rpc/index.js';
|
|
4
|
-
import { resolveCallInputs } from '../execution/utils.js';
|
|
5
|
-
import { getSocialRecoveryValidator, OWNABLE_VALIDATOR_ADDRESS, WEBAUTHN_VALIDATOR_ADDRESS, } from '../modules/validators/core.js';
|
|
6
|
-
import { addOwner, changeThreshold, removeOwner } from './ecdsa.js';
|
|
7
|
-
import { addOwner as addPasskeyOwner, changeThreshold as changePasskeyThreshold, removeOwner as removePasskeyOwner, } from './passkeys.js';
|
|
8
|
-
/**
|
|
9
|
-
* Set up social recovery
|
|
10
|
-
* @param guardians Guardians to use for recovery
|
|
11
|
-
* @param threshold Threshold for the guardians
|
|
12
|
-
* @returns Calls to set up social recovery
|
|
13
|
-
*/
|
|
14
|
-
function enable(guardians, threshold = 1) {
|
|
15
|
-
const module = getSocialRecoveryValidator(guardians, threshold);
|
|
16
|
-
return {
|
|
17
|
-
async resolve({ config }) {
|
|
18
|
-
return getModuleInstallationCalls(config, module);
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Recover an account's ownership (ECDSA)
|
|
24
|
-
* @param address Account address
|
|
25
|
-
* @param newOwners New owners
|
|
26
|
-
* @param chain Chain to recover ownership on
|
|
27
|
-
* @param provider Provider to use for the recovery
|
|
28
|
-
* @returns Calls to recover ownership
|
|
29
|
-
*/
|
|
30
|
-
async function recoverEcdsaOwnership(address, newOwners, chain, config) {
|
|
31
|
-
const publicClient = createPublicClient({
|
|
32
|
-
chain,
|
|
33
|
-
transport: createTransport(chain, config.provider),
|
|
34
|
-
});
|
|
35
|
-
// Read the existing config
|
|
36
|
-
const results = await publicClient.multicall({
|
|
37
|
-
contracts: [
|
|
38
|
-
{
|
|
39
|
-
address: OWNABLE_VALIDATOR_ADDRESS,
|
|
40
|
-
abi: [
|
|
41
|
-
{
|
|
42
|
-
inputs: [
|
|
43
|
-
{ internalType: 'address', name: 'account', type: 'address' },
|
|
44
|
-
],
|
|
45
|
-
name: 'getOwners',
|
|
46
|
-
outputs: [
|
|
47
|
-
{
|
|
48
|
-
internalType: 'address[]',
|
|
49
|
-
name: 'ownersArray',
|
|
50
|
-
type: 'address[]',
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
stateMutability: 'view',
|
|
54
|
-
type: 'function',
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
functionName: 'getOwners',
|
|
58
|
-
args: [address],
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
address: OWNABLE_VALIDATOR_ADDRESS,
|
|
62
|
-
abi: [
|
|
63
|
-
{
|
|
64
|
-
inputs: [
|
|
65
|
-
{ internalType: 'address', name: 'account', type: 'address' },
|
|
66
|
-
],
|
|
67
|
-
name: 'threshold',
|
|
68
|
-
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
|
69
|
-
stateMutability: 'view',
|
|
70
|
-
type: 'function',
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
functionName: 'threshold',
|
|
74
|
-
args: [address],
|
|
75
|
-
},
|
|
76
|
-
],
|
|
77
|
-
});
|
|
78
|
-
const existingOwnersResult = results[0];
|
|
79
|
-
const existingThresholdResult = results[1];
|
|
80
|
-
if (existingOwnersResult.error || existingThresholdResult.error) {
|
|
81
|
-
throw new Error('Failed to read existing owners or threshold');
|
|
82
|
-
}
|
|
83
|
-
const existingOwners = existingOwnersResult.result;
|
|
84
|
-
const existingThreshold = existingThresholdResult.result;
|
|
85
|
-
const normalizedExistingOwners = existingOwners.map((owner) => owner.toLowerCase());
|
|
86
|
-
const callInputs = [];
|
|
87
|
-
// Convert new owners config to addresses and threshold
|
|
88
|
-
const newOwnerAddresses = newOwners.accounts
|
|
89
|
-
.map((account) => account.address.toLowerCase())
|
|
90
|
-
.sort();
|
|
91
|
-
const newThreshold = newOwners.threshold ?? 1;
|
|
92
|
-
// Check if threshold needs to be updated
|
|
93
|
-
if (Number(existingThreshold) !== newThreshold) {
|
|
94
|
-
callInputs.push(changeThreshold(newThreshold));
|
|
95
|
-
}
|
|
96
|
-
const ownersToAdd = newOwnerAddresses.filter((owner) => !normalizedExistingOwners.includes(owner));
|
|
97
|
-
const ownersToRemove = normalizedExistingOwners.filter((owner) => !newOwnerAddresses.includes(owner));
|
|
98
|
-
// Maintain the list as making changes to keep track of the previous owner for removals
|
|
99
|
-
// Note: new owners are added to the START of the linked list
|
|
100
|
-
let currentOwners = [...normalizedExistingOwners];
|
|
101
|
-
for (const owner of ownersToAdd) {
|
|
102
|
-
callInputs.push(addOwner(owner));
|
|
103
|
-
currentOwners.unshift(owner);
|
|
104
|
-
}
|
|
105
|
-
for (const ownerToRemove of ownersToRemove) {
|
|
106
|
-
const ownerIndex = currentOwners.indexOf(ownerToRemove);
|
|
107
|
-
let prevOwner;
|
|
108
|
-
if (ownerIndex === 0) {
|
|
109
|
-
// If it's the first owner, use the sentinel address
|
|
110
|
-
prevOwner = '0x0000000000000000000000000000000000000001';
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
prevOwner = currentOwners[ownerIndex - 1];
|
|
114
|
-
}
|
|
115
|
-
callInputs.push(removeOwner(prevOwner, ownerToRemove));
|
|
116
|
-
currentOwners = currentOwners.filter((owner) => owner !== ownerToRemove);
|
|
117
|
-
}
|
|
118
|
-
const calls = await resolveCallInputs(callInputs, config, chain, address);
|
|
119
|
-
return calls;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Recover an account's ownership (Passkey)
|
|
123
|
-
* @param address Account address
|
|
124
|
-
* @param oldCredentials Old credentials to be replaced (with pubKeyX, pubKeyY)
|
|
125
|
-
* @param newOwners New passkey owners
|
|
126
|
-
* @param chain Chain to recover ownership on
|
|
127
|
-
* @param provider Provider to use for the recovery
|
|
128
|
-
* @returns Calls to recover ownership
|
|
129
|
-
*/
|
|
130
|
-
async function recoverPasskeyOwnership(address, oldCredentials, newOwners, chain, config) {
|
|
131
|
-
const publicClient = createPublicClient({
|
|
132
|
-
chain,
|
|
133
|
-
transport: createTransport(chain, config.provider),
|
|
134
|
-
});
|
|
135
|
-
const existingThreshold = await publicClient.readContract({
|
|
136
|
-
address: WEBAUTHN_VALIDATOR_ADDRESS,
|
|
137
|
-
abi: [
|
|
138
|
-
{
|
|
139
|
-
inputs: [{ internalType: 'address', name: 'account', type: 'address' }],
|
|
140
|
-
name: 'threshold',
|
|
141
|
-
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
|
142
|
-
stateMutability: 'view',
|
|
143
|
-
type: 'function',
|
|
144
|
-
},
|
|
145
|
-
],
|
|
146
|
-
functionName: 'threshold',
|
|
147
|
-
args: [address],
|
|
148
|
-
});
|
|
149
|
-
const callInputs = [];
|
|
150
|
-
// Convert new owners config to credentials and threshold
|
|
151
|
-
const newCredentials = newOwners.accounts.map((account) => {
|
|
152
|
-
const publicKey = account.publicKey;
|
|
153
|
-
// Parse the public key hex string to extract x and y coordinates
|
|
154
|
-
const publicKeyBytes = publicKey.startsWith('0x')
|
|
155
|
-
? publicKey.slice(2)
|
|
156
|
-
: publicKey;
|
|
157
|
-
// The public key is 64 bytes: 32 bytes for x, 32 bytes for y
|
|
158
|
-
const x = BigInt(`0x${publicKeyBytes.slice(0, 64)}`);
|
|
159
|
-
const y = BigInt(`0x${publicKeyBytes.slice(64, 128)}`);
|
|
160
|
-
return {
|
|
161
|
-
pubKeyX: x,
|
|
162
|
-
pubKeyY: y,
|
|
163
|
-
requireUV: false, // Default to false for now
|
|
164
|
-
};
|
|
165
|
-
});
|
|
166
|
-
const newThreshold = newOwners.threshold ?? 1;
|
|
167
|
-
// Check if threshold needs to be updated
|
|
168
|
-
if (Number(existingThreshold) !== newThreshold) {
|
|
169
|
-
callInputs.push(changePasskeyThreshold(newThreshold));
|
|
170
|
-
}
|
|
171
|
-
// Compare existing and new credentials to determine what to add/remove
|
|
172
|
-
const existingCredentialKeys = oldCredentials.map((cred) => `${cred.pubKeyX.toString()}-${cred.pubKeyY.toString()}`);
|
|
173
|
-
const newCredentialKeys = newCredentials.map((cred) => `${cred.pubKeyX.toString()}-${cred.pubKeyY.toString()}`);
|
|
174
|
-
// Find credentials to add (new ones not in existing)
|
|
175
|
-
const credentialsToAdd = newCredentials.filter((cred) => !existingCredentialKeys.includes(`${cred.pubKeyX.toString()}-${cred.pubKeyY.toString()}`));
|
|
176
|
-
// Find credentials to remove (existing ones not in new)
|
|
177
|
-
const credentialsToRemove = oldCredentials.filter((cred) => !newCredentialKeys.includes(`${cred.pubKeyX.toString()}-${cred.pubKeyY.toString()}`));
|
|
178
|
-
// Remove old credentials first (important for security in recovery scenarios)
|
|
179
|
-
for (const credential of credentialsToRemove) {
|
|
180
|
-
callInputs.push(removePasskeyOwner(credential.pubKeyX, credential.pubKeyY));
|
|
181
|
-
}
|
|
182
|
-
// Then add new credentials
|
|
183
|
-
for (const credential of credentialsToAdd) {
|
|
184
|
-
callInputs.push(addPasskeyOwner(credential.pubKeyX, credential.pubKeyY, credential.requireUV));
|
|
185
|
-
}
|
|
186
|
-
const calls = await resolveCallInputs(callInputs, config, chain, address);
|
|
187
|
-
return calls;
|
|
188
|
-
}
|
|
189
|
-
export { enable, recoverEcdsaOwnership, recoverPasskeyOwnership };
|