@rhinestone/sdk 2.0.0-beta.3 → 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.
Files changed (107) hide show
  1. package/dist/src/accounts/error.d.ts +2 -9
  2. package/dist/src/accounts/error.d.ts.map +1 -1
  3. package/dist/src/accounts/error.js +5 -11
  4. package/dist/src/accounts/hca.d.ts +25 -0
  5. package/dist/src/accounts/hca.d.ts.map +1 -0
  6. package/dist/src/accounts/hca.js +145 -0
  7. package/dist/src/accounts/index.d.ts +9 -9
  8. package/dist/src/accounts/index.d.ts.map +1 -1
  9. package/dist/src/accounts/index.js +112 -41
  10. package/dist/src/accounts/kernel.d.ts +1 -2
  11. package/dist/src/accounts/kernel.d.ts.map +1 -1
  12. package/dist/src/accounts/kernel.js +1 -8
  13. package/dist/src/accounts/nexus.d.ts +3 -2
  14. package/dist/src/accounts/nexus.d.ts.map +1 -1
  15. package/dist/src/accounts/nexus.js +33 -8
  16. package/dist/src/accounts/safe.d.ts +1 -2
  17. package/dist/src/accounts/safe.d.ts.map +1 -1
  18. package/dist/src/accounts/safe.js +3 -9
  19. package/dist/src/accounts/signing/common.d.ts +1 -4
  20. package/dist/src/accounts/signing/common.d.ts.map +1 -1
  21. package/dist/src/accounts/signing/common.js +7 -11
  22. package/dist/src/accounts/signing/message.d.ts.map +1 -1
  23. package/dist/src/accounts/signing/message.js +1 -4
  24. package/dist/src/accounts/signing/typedData.d.ts.map +1 -1
  25. package/dist/src/accounts/signing/typedData.js +1 -4
  26. package/dist/src/accounts/startale.d.ts +1 -2
  27. package/dist/src/accounts/startale.d.ts.map +1 -1
  28. package/dist/src/accounts/startale.js +2 -5
  29. package/dist/src/actions/ecdsa.js +5 -5
  30. package/dist/src/actions/index.js +2 -2
  31. package/dist/src/actions/mfa.js +2 -2
  32. package/dist/src/actions/passkeys.js +2 -2
  33. package/dist/src/actions/smart-sessions.d.ts +29 -5
  34. package/dist/src/actions/smart-sessions.d.ts.map +1 -1
  35. package/dist/src/actions/smart-sessions.js +38 -10
  36. package/dist/src/errors/index.d.ts +4 -4
  37. package/dist/src/errors/index.d.ts.map +1 -1
  38. package/dist/src/errors/index.js +6 -6
  39. package/dist/src/execution/error.d.ts +8 -21
  40. package/dist/src/execution/error.d.ts.map +1 -1
  41. package/dist/src/execution/error.js +7 -21
  42. package/dist/src/execution/index.d.ts +17 -17
  43. package/dist/src/execution/index.d.ts.map +1 -1
  44. package/dist/src/execution/index.js +22 -41
  45. package/dist/src/execution/utils.d.ts +15 -11
  46. package/dist/src/execution/utils.d.ts.map +1 -1
  47. package/dist/src/execution/utils.js +279 -75
  48. package/dist/src/index.d.ts +236 -37
  49. package/dist/src/index.d.ts.map +1 -1
  50. package/dist/src/index.js +60 -115
  51. package/dist/src/jwt-server/jcs.d.ts +1 -1
  52. package/dist/src/jwt-server/jcs.js +4 -2
  53. package/dist/src/modules/index.d.ts.map +1 -1
  54. package/dist/src/modules/index.js +0 -5
  55. package/dist/src/modules/read.d.ts +3 -2
  56. package/dist/src/modules/read.d.ts.map +1 -1
  57. package/dist/src/modules/read.js +33 -4
  58. package/dist/src/modules/validators/core.d.ts +5 -5
  59. package/dist/src/modules/validators/core.d.ts.map +1 -1
  60. package/dist/src/modules/validators/core.js +45 -34
  61. package/dist/src/modules/validators/cross-chain-permits.d.ts +11 -0
  62. package/dist/src/modules/validators/cross-chain-permits.d.ts.map +1 -0
  63. package/dist/src/modules/validators/cross-chain-permits.js +76 -0
  64. package/dist/src/modules/validators/permissions.d.ts +1 -0
  65. package/dist/src/modules/validators/permissions.d.ts.map +1 -1
  66. package/dist/src/modules/validators/permissions.js +162 -17
  67. package/dist/src/modules/validators/policies/claim/arbiters.d.ts +22 -0
  68. package/dist/src/modules/validators/policies/claim/arbiters.d.ts.map +1 -0
  69. package/dist/src/modules/validators/policies/claim/arbiters.js +57 -0
  70. package/dist/src/modules/validators/smart-sessions.d.ts +38 -9
  71. package/dist/src/modules/validators/smart-sessions.d.ts.map +1 -1
  72. package/dist/src/modules/validators/smart-sessions.js +509 -92
  73. package/dist/src/orchestrator/caip2.d.ts +9 -3
  74. package/dist/src/orchestrator/caip2.d.ts.map +1 -1
  75. package/dist/src/orchestrator/caip2.js +40 -5
  76. package/dist/src/orchestrator/client.d.ts.map +1 -1
  77. package/dist/src/orchestrator/client.js +44 -21
  78. package/dist/src/orchestrator/consts.d.ts +1 -1
  79. package/dist/src/orchestrator/consts.d.ts.map +1 -1
  80. package/dist/src/orchestrator/consts.js +1 -1
  81. package/dist/src/orchestrator/destinations.d.ts +24 -0
  82. package/dist/src/orchestrator/destinations.d.ts.map +1 -0
  83. package/dist/src/orchestrator/destinations.js +55 -0
  84. package/dist/src/orchestrator/error.d.ts +87 -4
  85. package/dist/src/orchestrator/error.d.ts.map +1 -1
  86. package/dist/src/orchestrator/error.js +237 -3
  87. package/dist/src/orchestrator/index.d.ts +6 -5
  88. package/dist/src/orchestrator/index.d.ts.map +1 -1
  89. package/dist/src/orchestrator/index.js +4 -3
  90. package/dist/src/orchestrator/registry.d.ts +2 -1
  91. package/dist/src/orchestrator/registry.d.ts.map +1 -1
  92. package/dist/src/orchestrator/registry.js +13 -0
  93. package/dist/src/orchestrator/types.d.ts +114 -28
  94. package/dist/src/orchestrator/types.d.ts.map +1 -1
  95. package/dist/src/orchestrator/types.js +1 -5
  96. package/dist/src/smart-sessions/index.d.ts +5 -0
  97. package/dist/src/smart-sessions/index.d.ts.map +1 -0
  98. package/dist/src/smart-sessions/index.js +6 -0
  99. package/dist/src/types.d.ts +298 -29
  100. package/dist/src/types.d.ts.map +1 -1
  101. package/dist/src/utils/index.d.ts +59 -0
  102. package/dist/src/utils/index.d.ts.map +1 -1
  103. package/dist/src/utils/index.js +59 -0
  104. package/package.json +4 -8
  105. package/dist/src/actions/recovery.d.ts +0 -33
  106. package/dist/src/actions/recovery.d.ts.map +0 -1
  107. package/dist/src/actions/recovery.js +0 -189
@@ -2,12 +2,55 @@ import type { Account, Address, Hex } from 'viem';
2
2
  import { getSetup as experimental_getModuleSetup } from '../modules/index.js';
3
3
  import type { RhinestoneAccountConfig } from '../types.js';
4
4
  import { walletClientToAccount, wrapParaAccount } from './walletClient.js';
5
+ /**
6
+ * Compute the v0 (legacy) initialization data for an account configuration.
7
+ *
8
+ * Use this to reconstruct the `initData` for an account originally created with
9
+ * the Rhinestone SDK v0, then pass it back into `createAccount`.
10
+ * @param config Account configuration
11
+ * @returns The account address, factory, factory data, and whether the intent executor is installed
12
+ * @example
13
+ * ```ts
14
+ * import { experimental_getV0InitData } from '@rhinestone/sdk/utils'
15
+ *
16
+ * const initData = experimental_getV0InitData({
17
+ * owners: { type: 'ecdsa', accounts: [owner] },
18
+ * })
19
+ *
20
+ * const account = await sdk.createAccount({
21
+ * owners: { type: 'ecdsa', accounts: [owner] },
22
+ * initData,
23
+ * })
24
+ * ```
25
+ */
5
26
  declare function experimental_getV0InitData(config: RhinestoneAccountConfig): {
6
27
  address: Address;
7
28
  factory: Address;
8
29
  factoryData: Hex;
9
30
  intentExecutorInstalled: boolean;
10
31
  };
32
+ /**
33
+ * Compute the Rhinestone initialization data for an account configuration.
34
+ *
35
+ * Use this to reconstruct the `initData` for an account originally created with
36
+ * the Rhinestone SDK, then pass it back into `createAccount` instead of
37
+ * providing the factory and factory data manually.
38
+ * @param config Account configuration
39
+ * @returns The account address, plus factory data when the account is not yet deployed
40
+ * @example
41
+ * ```ts
42
+ * import { experimental_getRhinestoneInitData } from '@rhinestone/sdk/utils'
43
+ *
44
+ * const initData = experimental_getRhinestoneInitData({
45
+ * owners: { type: 'ecdsa', accounts: [owner] },
46
+ * })
47
+ *
48
+ * const account = await sdk.createAccount({
49
+ * owners: { type: 'ecdsa', accounts: [owner] },
50
+ * initData,
51
+ * })
52
+ * ```
53
+ */
11
54
  declare function experimental_getRhinestoneInitData(config: RhinestoneAccountConfig): {
12
55
  address: Address;
13
56
  factory: Address;
@@ -16,6 +59,22 @@ declare function experimental_getRhinestoneInitData(config: RhinestoneAccountCon
16
59
  } | {
17
60
  address: Address;
18
61
  };
62
+ /**
63
+ * Create a view-only viem `Account` for an address. Any signing operation throws.
64
+ *
65
+ * Useful as an account owner when signing happens elsewhere (e.g. a server-held
66
+ * session signer), so the SDK can read from the account without holding a key.
67
+ * @param address Address to wrap
68
+ * @returns A viem account that can be read from but not signed with
69
+ * @example
70
+ * ```ts
71
+ * import { toViewOnlyAccount } from '@rhinestone/sdk/utils'
72
+ *
73
+ * const account = await sdk.createAccount({
74
+ * owners: { type: 'ecdsa', accounts: [toViewOnlyAccount(userAddress)] },
75
+ * })
76
+ * ```
77
+ */
19
78
  declare function toViewOnlyAccount(address: Address): Account;
20
79
  export { experimental_getV0InitData, experimental_getModuleSetup, experimental_getRhinestoneInitData, toViewOnlyAccount, walletClientToAccount, wrapParaAccount, };
21
80
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAGjD,OAAO,EAAE,QAAQ,IAAI,2BAA2B,EAAE,MAAM,YAAY,CAAA;AACpE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAEvE,iBAAS,0BAA0B,CAAC,MAAM,EAAE,uBAAuB,GAAG;IACpE,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,WAAW,EAAE,GAAG,CAAA;IAChB,uBAAuB,EAAE,OAAO,CAAA;CACjC,CAgBA;AAED,iBAAS,kCAAkC,CAAC,MAAM,EAAE,uBAAuB,GACvE;IACE,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,WAAW,EAAE,GAAG,CAAA;IAChB,uBAAuB,EAAE,OAAO,CAAA;CACjC,GACD;IACE,OAAO,EAAE,OAAO,CAAA;CACjB,CAmBJ;AAED,iBAAS,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAcpD;AAED,OAAO,EACL,0BAA0B,EAC1B,2BAA2B,EAC3B,kCAAkC,EAClC,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,GAChB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAGjD,OAAO,EAAE,QAAQ,IAAI,2BAA2B,EAAE,MAAM,YAAY,CAAA;AACpE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAEvE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,iBAAS,0BAA0B,CAAC,MAAM,EAAE,uBAAuB,GAAG;IACpE,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,WAAW,EAAE,GAAG,CAAA;IAChB,uBAAuB,EAAE,OAAO,CAAA;CACjC,CAgBA;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,iBAAS,kCAAkC,CAAC,MAAM,EAAE,uBAAuB,GACvE;IACE,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,WAAW,EAAE,GAAG,CAAA;IAChB,uBAAuB,EAAE,OAAO,CAAA;CACjC,GACD;IACE,OAAO,EAAE,OAAO,CAAA;CACjB,CAmBJ;AAED;;;;;;;;;;;;;;;GAeG;AACH,iBAAS,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAcpD;AAED,OAAO,EACL,0BAA0B,EAC1B,2BAA2B,EAC3B,kCAAkC,EAClC,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,GAChB,CAAA"}
@@ -2,6 +2,27 @@ import { toAccount } from 'viem/accounts';
2
2
  import { getAddress, getInitCode, getV0InitCode } from '../accounts/index.js';
3
3
  import { getSetup as experimental_getModuleSetup } from '../modules/index.js';
4
4
  import { walletClientToAccount, wrapParaAccount } from './walletClient.js';
5
+ /**
6
+ * Compute the v0 (legacy) initialization data for an account configuration.
7
+ *
8
+ * Use this to reconstruct the `initData` for an account originally created with
9
+ * the Rhinestone SDK v0, then pass it back into `createAccount`.
10
+ * @param config Account configuration
11
+ * @returns The account address, factory, factory data, and whether the intent executor is installed
12
+ * @example
13
+ * ```ts
14
+ * import { experimental_getV0InitData } from '@rhinestone/sdk/utils'
15
+ *
16
+ * const initData = experimental_getV0InitData({
17
+ * owners: { type: 'ecdsa', accounts: [owner] },
18
+ * })
19
+ *
20
+ * const account = await sdk.createAccount({
21
+ * owners: { type: 'ecdsa', accounts: [owner] },
22
+ * initData,
23
+ * })
24
+ * ```
25
+ */
5
26
  function experimental_getV0InitData(config) {
6
27
  const initCode = getV0InitCode(config);
7
28
  if (!initCode) {
@@ -19,6 +40,28 @@ function experimental_getV0InitData(config) {
19
40
  intentExecutorInstalled: true,
20
41
  };
21
42
  }
43
+ /**
44
+ * Compute the Rhinestone initialization data for an account configuration.
45
+ *
46
+ * Use this to reconstruct the `initData` for an account originally created with
47
+ * the Rhinestone SDK, then pass it back into `createAccount` instead of
48
+ * providing the factory and factory data manually.
49
+ * @param config Account configuration
50
+ * @returns The account address, plus factory data when the account is not yet deployed
51
+ * @example
52
+ * ```ts
53
+ * import { experimental_getRhinestoneInitData } from '@rhinestone/sdk/utils'
54
+ *
55
+ * const initData = experimental_getRhinestoneInitData({
56
+ * owners: { type: 'ecdsa', accounts: [owner] },
57
+ * })
58
+ *
59
+ * const account = await sdk.createAccount({
60
+ * owners: { type: 'ecdsa', accounts: [owner] },
61
+ * initData,
62
+ * })
63
+ * ```
64
+ */
22
65
  function experimental_getRhinestoneInitData(config) {
23
66
  const initCode = getInitCode(config);
24
67
  if (!initCode) {
@@ -40,6 +83,22 @@ function experimental_getRhinestoneInitData(config) {
40
83
  };
41
84
  }
42
85
  }
86
+ /**
87
+ * Create a view-only viem `Account` for an address. Any signing operation throws.
88
+ *
89
+ * Useful as an account owner when signing happens elsewhere (e.g. a server-held
90
+ * session signer), so the SDK can read from the account without holding a key.
91
+ * @param address Address to wrap
92
+ * @returns A viem account that can be read from but not signed with
93
+ * @example
94
+ * ```ts
95
+ * import { toViewOnlyAccount } from '@rhinestone/sdk/utils'
96
+ *
97
+ * const account = await sdk.createAccount({
98
+ * owners: { type: 'ecdsa', accounts: [toViewOnlyAccount(userAddress)] },
99
+ * })
100
+ * ```
101
+ */
43
102
  function toViewOnlyAccount(address) {
44
103
  const errorMessage = 'Signing is not supported for view-only accounts';
45
104
  return toAccount({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhinestone/sdk",
3
- "version": "2.0.0-beta.3",
3
+ "version": "2.0.0-beta.30",
4
4
  "description": "End-to-end chain abstraction and modularity toolkit",
5
5
  "author": {
6
6
  "name": "Rhinestone",
@@ -43,10 +43,6 @@
43
43
  "types": "./dist/src/actions/smart-sessions.d.ts",
44
44
  "import": "./dist/src/actions/smart-sessions.js"
45
45
  },
46
- "./actions/recovery": {
47
- "types": "./dist/src/actions/recovery.d.ts",
48
- "import": "./dist/src/actions/recovery.js"
49
- },
50
46
  "./errors": {
51
47
  "types": "./dist/src/errors/index.d.ts",
52
48
  "import": "./dist/src/errors/index.js"
@@ -56,8 +52,8 @@
56
52
  "import": "./dist/src/utils/index.js"
57
53
  },
58
54
  "./smart-sessions": {
59
- "types": "./dist/src/modules/validators/smart-sessions.d.ts",
60
- "import": "./dist/src/modules/validators/smart-sessions.js"
55
+ "types": "./dist/src/smart-sessions/index.d.ts",
56
+ "import": "./dist/src/smart-sessions/index.js"
61
57
  },
62
58
  "./jwt-server": {
63
59
  "types": "./dist/src/jwt-server/index.d.ts",
@@ -79,7 +75,7 @@
79
75
  "access": "public"
80
76
  },
81
77
  "dependencies": {
82
- "@rhinestone/shared-configs": "1.4.139",
78
+ "@rhinestone/shared-configs": "1.6.7",
83
79
  "solady": "^0.1.26"
84
80
  },
85
81
  "peerDependencies": {
@@ -1,33 +0,0 @@
1
- import { type Account, type Address, type Chain } from 'viem';
2
- import type { CalldataInput, LazyCallInput, OwnableValidatorConfig, RhinestoneConfig, WebauthnValidatorConfig } from '../types.js';
3
- /**
4
- * Set up social recovery
5
- * @param guardians Guardians to use for recovery
6
- * @param threshold Threshold for the guardians
7
- * @returns Calls to set up social recovery
8
- */
9
- declare function enable(guardians: Account[], threshold?: number): LazyCallInput;
10
- /**
11
- * Recover an account's ownership (ECDSA)
12
- * @param address Account address
13
- * @param newOwners New owners
14
- * @param chain Chain to recover ownership on
15
- * @param provider Provider to use for the recovery
16
- * @returns Calls to recover ownership
17
- */
18
- declare function recoverEcdsaOwnership(address: Address, newOwners: OwnableValidatorConfig, chain: Chain, config: RhinestoneConfig): Promise<CalldataInput[]>;
19
- /**
20
- * Recover an account's ownership (Passkey)
21
- * @param address Account address
22
- * @param oldCredentials Old credentials to be replaced (with pubKeyX, pubKeyY)
23
- * @param newOwners New passkey owners
24
- * @param chain Chain to recover ownership on
25
- * @param provider Provider to use for the recovery
26
- * @returns Calls to recover ownership
27
- */
28
- declare function recoverPasskeyOwnership(address: Address, oldCredentials: {
29
- pubKeyX: bigint;
30
- pubKeyY: bigint;
31
- }[], newOwners: WebauthnValidatorConfig, chain: Chain, config: RhinestoneConfig): Promise<CalldataInput[]>;
32
- export { enable, recoverEcdsaOwnership, recoverPasskeyOwnership };
33
- //# sourceMappingURL=recovery.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../../../actions/recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,KAAK,EAEX,MAAM,MAAM,CAAA;AASb,OAAO,KAAK,EACV,aAAa,EAEb,aAAa,EACb,sBAAsB,EACtB,gBAAgB,EAChB,uBAAuB,EACxB,MAAM,UAAU,CAAA;AAQjB;;;;;GAKG;AACH,iBAAS,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,SAAS,SAAI,GAAG,aAAa,CAOlE;AAED;;;;;;;GAOG;AACH,iBAAe,qBAAqB,CAClC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,sBAAsB,EACjC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,aAAa,EAAE,CAAC,CAwG1B;AAED;;;;;;;;GAQG;AACH,iBAAe,uBAAuB,CACpC,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EAAE,EACtD,SAAS,EAAE,uBAAuB,EAClC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,aAAa,EAAE,CAAC,CA0F1B;AAED,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,CAAA"}
@@ -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 };