rise-wallet 0.3.0 → 0.3.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 (98) hide show
  1. package/dist/cli/bin/commands-f0vN9Upd.js +50 -0
  2. package/dist/cli/bin/index.js +1 -1
  3. package/dist/core/Chains.d.ts +14 -283
  4. package/dist/core/Chains.d.ts.map +1 -1
  5. package/dist/core/Dialog.d.ts.map +1 -1
  6. package/dist/core/Dialog.js +8 -0
  7. package/dist/core/Dialog.js.map +1 -1
  8. package/dist/core/Porto.d.ts +201 -293
  9. package/dist/core/Porto.d.ts.map +1 -1
  10. package/dist/core/internal/_generated/chains.d.ts +1 -1
  11. package/dist/core/internal/_generated/chains.d.ts.map +1 -1
  12. package/dist/core/internal/_generated/chains.js +1 -1
  13. package/dist/core/internal/_generated/chains.js.map +1 -1
  14. package/dist/core/internal/mode.d.ts +4 -0
  15. package/dist/core/internal/mode.d.ts.map +1 -1
  16. package/dist/core/internal/mode.js.map +1 -1
  17. package/dist/core/internal/modes/dialog.d.ts +47 -7
  18. package/dist/core/internal/modes/dialog.d.ts.map +1 -1
  19. package/dist/core/internal/modes/reactNative.d.ts +187 -10
  20. package/dist/core/internal/modes/reactNative.d.ts.map +1 -1
  21. package/dist/core/internal/modes/relay.d.ts +140 -3
  22. package/dist/core/internal/modes/relay.d.ts.map +1 -1
  23. package/dist/core/internal/modes/relay.js +102 -26
  24. package/dist/core/internal/modes/relay.js.map +1 -1
  25. package/dist/core/internal/permissions.d.ts +1 -1
  26. package/dist/core/internal/permissionsRequest.d.ts +1 -1
  27. package/dist/core/internal/provider.d.ts.map +1 -1
  28. package/dist/core/internal/provider.js +12 -1
  29. package/dist/core/internal/provider.js.map +1 -1
  30. package/dist/core/internal/relay/rpcSchema.d.ts +3 -0
  31. package/dist/core/internal/relay/rpcSchema.d.ts.map +1 -1
  32. package/dist/core/internal/relay/schema/rpc.d.ts +23 -0
  33. package/dist/core/internal/relay/schema/rpc.d.ts.map +1 -1
  34. package/dist/core/internal/relay/schema/rpc.js +18 -0
  35. package/dist/core/internal/relay/schema/rpc.js.map +1 -1
  36. package/dist/core/internal/schema/capabilities.d.ts +2 -2
  37. package/dist/core/internal/schema/key.d.ts +2 -2
  38. package/dist/core/internal/schema/key.d.ts.map +1 -1
  39. package/dist/core/internal/schema/key.js +1 -0
  40. package/dist/core/internal/schema/key.js.map +1 -1
  41. package/dist/core/internal/schema/permissions.d.ts +2 -2
  42. package/dist/core/internal/schema/request.d.ts +18 -16
  43. package/dist/core/internal/schema/request.d.ts.map +1 -1
  44. package/dist/core/internal/schema/rpc.d.ts +52 -46
  45. package/dist/core/internal/schema/rpc.d.ts.map +1 -1
  46. package/dist/core/internal/schema/rpc.js +1 -0
  47. package/dist/core/internal/schema/rpc.js.map +1 -1
  48. package/dist/core/react-native/Porto.d.ts +201 -293
  49. package/dist/core/react-native/Porto.d.ts.map +1 -1
  50. package/dist/remote/Events.d.ts.map +1 -1
  51. package/dist/remote/Events.js +10 -3
  52. package/dist/remote/Events.js.map +1 -1
  53. package/dist/remote/Hooks.d.ts +42 -38
  54. package/dist/remote/Hooks.d.ts.map +1 -1
  55. package/dist/remote/Porto.d.ts +154 -286
  56. package/dist/remote/Porto.d.ts.map +1 -1
  57. package/dist/trusted-hosts.d.ts.map +1 -1
  58. package/dist/trusted-hosts.js +5 -0
  59. package/dist/trusted-hosts.js.map +1 -1
  60. package/dist/tsconfig.tmp.tsbuildinfo +1 -1
  61. package/dist/viem/Account.d.ts +3 -0
  62. package/dist/viem/Account.d.ts.map +1 -1
  63. package/dist/viem/Account.js +16 -12
  64. package/dist/viem/Account.js.map +1 -1
  65. package/dist/viem/Key.d.ts +96 -1
  66. package/dist/viem/Key.d.ts.map +1 -1
  67. package/dist/viem/Key.js +102 -3
  68. package/dist/viem/Key.js.map +1 -1
  69. package/dist/viem/RelayActions.d.ts +12 -1
  70. package/dist/viem/RelayActions.d.ts.map +1 -1
  71. package/dist/viem/RelayActions.js +8 -3
  72. package/dist/viem/RelayActions.js.map +1 -1
  73. package/dist/viem/internal/provider.d.ts +9 -0
  74. package/dist/viem/internal/provider.d.ts.map +1 -0
  75. package/dist/viem/internal/provider.js +15 -0
  76. package/dist/viem/internal/provider.js.map +1 -0
  77. package/dist/viem/internal/relayActions.d.ts +16 -0
  78. package/dist/viem/internal/relayActions.d.ts.map +1 -1
  79. package/dist/viem/internal/relayActions.js +29 -0
  80. package/dist/viem/internal/relayActions.js.map +1 -1
  81. package/package.json +3 -2
  82. package/src/core/Dialog.ts +10 -0
  83. package/src/core/internal/_generated/chains.ts +1 -1
  84. package/src/core/internal/mode.ts +5 -1
  85. package/src/core/internal/modes/relay.ts +158 -56
  86. package/src/core/internal/provider.ts +14 -0
  87. package/src/core/internal/relay/rpcSchema.ts +4 -0
  88. package/src/core/internal/relay/schema/rpc.ts +23 -0
  89. package/src/core/internal/schema/key.ts +1 -0
  90. package/src/core/internal/schema/rpc.ts +1 -0
  91. package/src/remote/Events.ts +10 -3
  92. package/src/trusted-hosts.ts +5 -0
  93. package/src/viem/Account.ts +30 -12
  94. package/src/viem/Key.ts +163 -4
  95. package/src/viem/RelayActions.ts +30 -8
  96. package/src/viem/internal/provider.ts +19 -0
  97. package/src/viem/internal/relayActions.ts +42 -0
  98. package/dist/cli/bin/commands-GxQUW4ck.js +0 -50
package/src/viem/Key.ts CHANGED
@@ -13,7 +13,7 @@ import * as TypedData from 'ox/TypedData'
13
13
  import * as Value from 'ox/Value'
14
14
  import * as WebAuthnP256 from 'ox/WebAuthnP256'
15
15
  import * as WebCryptoP256 from 'ox/WebCryptoP256'
16
- import { zeroAddress } from 'viem'
16
+ import { type Chain, getTypesForEIP712Domain, zeroAddress } from 'viem'
17
17
  import * as Call from '../core/internal/call.js'
18
18
  import type * as RelayKey_schema from '../core/internal/relay/schema/key.js'
19
19
  import type * as RelayPermission_schema from '../core/internal/relay/schema/permission.js'
@@ -30,6 +30,8 @@ import type {
30
30
  UnionRequiredBy,
31
31
  } from '../core/internal/types.js'
32
32
  import type * as Storage from '../core/Storage.js'
33
+ import { getProvider } from './internal/provider.js'
34
+ import type { prepareCalls } from './internal/relayActions.js'
33
35
 
34
36
  type PrivateKeyFn = () => Hex.Hex
35
37
 
@@ -48,7 +50,12 @@ export type BaseKey<
48
50
  >
49
51
 
50
52
  export type Key = OneOf<
51
- AddressKey | P256Key | Secp256k1Key | WebCryptoKey | WebAuthnKey
53
+ | AddressKey
54
+ | P256Key
55
+ | Secp256k1Key
56
+ | WebCryptoKey
57
+ | WebAuthnKey
58
+ | Eip1193ProviderKey
52
59
  >
53
60
  export type AddressKey = BaseKey<'address'>
54
61
  export type P256Key = BaseKey<'p256', PrivateKeyFn>
@@ -66,6 +73,12 @@ export type WebAuthnKey = BaseKey<
66
73
  }
67
74
  >
68
75
  >
76
+ export type Eip1193ProviderKey = BaseKey<
77
+ 'eip1193provider',
78
+ {
79
+ rdns: string
80
+ }
81
+ >
69
82
 
70
83
  export type Permissions = Key_schema.Permissions
71
84
 
@@ -116,6 +129,7 @@ export const fromSerializedSpendPeriod = {
116
129
  /** Key type to Relay key type mapping. */
117
130
  export const toRelayKeyType = {
118
131
  address: 'secp256k1',
132
+ eip1193provider: 'secp256k1',
119
133
  p256: 'p256',
120
134
  secp256k1: 'secp256k1',
121
135
  'webauthn-p256': 'webauthnp256',
@@ -130,6 +144,7 @@ export const toRelayKeyRole = {
130
144
  /** Key type to serialized (contract-compatible) key type mapping. */
131
145
  export const toSerializedKeyType = {
132
146
  address: 2,
147
+ eip1193provider: 2,
133
148
  p256: 0,
134
149
  secp256k1: 2,
135
150
  'webauthn-p256': 1,
@@ -378,6 +393,38 @@ export declare namespace createWebCryptoP256 {
378
393
  >
379
394
  }
380
395
 
396
+ export async function createEip1193Provider(
397
+ parameters: createEip1193Provider.Parameters,
398
+ ) {
399
+ const { rdns } = parameters
400
+
401
+ const { provider = undefined } = (await getProvider({ rdns })) ?? {}
402
+
403
+ if (!provider) {
404
+ throw new Error('No provider found')
405
+ }
406
+
407
+ const [account] = await provider.request({
408
+ method: 'eth_requestAccounts',
409
+ })
410
+
411
+ if (!account) {
412
+ throw new Error('No account found')
413
+ }
414
+
415
+ return fromEip1193Provider({
416
+ ...parameters,
417
+ account,
418
+ })
419
+ }
420
+
421
+ export declare namespace createEip1193Provider {
422
+ type Parameters = Pick<
423
+ fromEip1193Provider.Parameters,
424
+ 'expiry' | 'feeToken' | 'permissions' | 'role' | 'rdns'
425
+ >
426
+ }
427
+
381
428
  /**
382
429
  * Deserializes a key from its serialized format.
383
430
  *
@@ -452,7 +499,11 @@ export function from<type extends Key['type']>(
452
499
  const publicKey = (() => {
453
500
  const publicKey = key.publicKey
454
501
  if (publicKey === '0x') return publicKey
455
- if (type === 'secp256k1' || type === 'address') {
502
+ if (
503
+ type === 'secp256k1' ||
504
+ type === 'address' ||
505
+ type === 'eip1193provider'
506
+ ) {
456
507
  const isAddress =
457
508
  Hex.size(publicKey) === 20 ||
458
509
  Hex.toBigInt(Hex.slice(publicKey, 0, 12)) === 0n
@@ -833,6 +884,31 @@ export declare namespace fromWebCryptoP256 {
833
884
  }
834
885
  }
835
886
 
887
+ export function fromEip1193Provider(
888
+ parameters: fromEip1193Provider.Parameters,
889
+ ) {
890
+ const { account, rdns } = parameters
891
+
892
+ return from({
893
+ ...parameters,
894
+ privateKey: {
895
+ rdns,
896
+ },
897
+ publicKey: account,
898
+ type: 'eip1193provider',
899
+ })
900
+ }
901
+
902
+ export declare namespace fromEip1193Provider {
903
+ type Parameters = Pick<
904
+ from.Value,
905
+ 'expiry' | 'feeToken' | 'permissions' | 'role'
906
+ > & {
907
+ rdns: string
908
+ account: Hex.Hex
909
+ }
910
+ }
911
+
836
912
  /**
837
913
  * Hashes a key.
838
914
  *
@@ -895,7 +971,7 @@ export function serialize(key: Key): Serialized {
895
971
  }
896
972
 
897
973
  export async function sign(key: Key, parameters: sign.Parameters) {
898
- const { address, storage, webAuthn, wrap = true } = parameters
974
+ const { address, storage, webAuthn, wrap = true, typedData } = parameters
899
975
  const { privateKey, publicKey, type: keyType } = key
900
976
 
901
977
  if (!privateKey)
@@ -1003,6 +1079,85 @@ export async function sign(key: Key, parameters: sign.Parameters) {
1003
1079
  })
1004
1080
  return [signature, false]
1005
1081
  }
1082
+ if (keyType === 'eip1193provider') {
1083
+ const { provider = undefined } =
1084
+ (await getProvider({ rdns: privateKey.rdns })) ?? {}
1085
+
1086
+ if (!provider) throw new Error(`No provider found for key "${key.id}"`)
1087
+
1088
+ if (!typedData) {
1089
+ const signature = await provider.request({
1090
+ method: 'personal_sign',
1091
+ params: [payload, publicKey],
1092
+ })
1093
+ return [signature, false]
1094
+ }
1095
+
1096
+ if (typedData.domain?.chainId) {
1097
+ const chainId = typedData.domain.chainId
1098
+ try {
1099
+ await provider.request({
1100
+ method: 'wallet_switchEthereumChain',
1101
+ params: [{ chainId: `0x${typedData.domain.chainId.toString(16)}` }],
1102
+ })
1103
+ } catch (error: any) {
1104
+ if ('code' in error && error.code === 4902) {
1105
+ const chains = (await import('viem/chains')) as unknown as Record<
1106
+ string,
1107
+ Chain
1108
+ >
1109
+
1110
+ const chain = Object.values(chains).find(
1111
+ (chain) => chain.id === chainId,
1112
+ )
1113
+
1114
+ if (!chain)
1115
+ throw new Error(
1116
+ `Not connected to chain ${typedData.domain.chainId}`,
1117
+ )
1118
+
1119
+ await provider.request({
1120
+ method: 'wallet_addEthereumChain',
1121
+ params: [
1122
+ {
1123
+ blockExplorerUrls: chain.blockExplorers?.default.url
1124
+ ? [chain.blockExplorers.default.url]
1125
+ : undefined,
1126
+ chainId: `0x${chain.id.toString(16)}`,
1127
+ chainName: chain.name,
1128
+ nativeCurrency: {
1129
+ decimals: chain.nativeCurrency.decimals,
1130
+ name: chain.nativeCurrency.name,
1131
+ symbol: chain.nativeCurrency.symbol,
1132
+ },
1133
+ rpcUrls: chain.rpcUrls.default.http,
1134
+ },
1135
+ ],
1136
+ })
1137
+ } else {
1138
+ throw error
1139
+ }
1140
+ }
1141
+ }
1142
+
1143
+ const signature = await provider.request({
1144
+ method: 'eth_signTypedData_v4',
1145
+ params: [
1146
+ publicKey,
1147
+ JSON.stringify({
1148
+ ...typedData,
1149
+ types: {
1150
+ EIP712Domain: getTypesForEIP712Domain({
1151
+ domain: typedData.domain,
1152
+ }),
1153
+ ...typedData.types,
1154
+ },
1155
+ }),
1156
+ ],
1157
+ })
1158
+
1159
+ return [signature, false]
1160
+ }
1006
1161
  throw new Error(
1007
1162
  `Key type "${keyType}" is not supported.\n\nKey:\n` +
1008
1163
  Json.stringify(key, null, 2),
@@ -1047,6 +1202,10 @@ export declare namespace sign {
1047
1202
  * @default true
1048
1203
  */
1049
1204
  wrap?: boolean | undefined
1205
+ typedData?:
1206
+ | prepareCalls.ReturnType['typedData']
1207
+ | TypedData.Definition
1208
+ | undefined
1050
1209
  }
1051
1210
  }
1052
1211
 
@@ -25,6 +25,7 @@ import * as Key from './Key.js'
25
25
 
26
26
  export {
27
27
  addFaucetFunds,
28
+ getAccount,
28
29
  getAssets,
29
30
  getAuthorization,
30
31
  getCallsStatus,
@@ -517,7 +518,7 @@ export async function sendCalls<
517
518
  if (pre.signature) return pre
518
519
 
519
520
  const { authorizeKeys, key, calls, revokeKeys } = pre
520
- const { context, digest } = await prepareCalls(client, {
521
+ const { context, digest, typedData } = await prepareCalls(client, {
521
522
  account: account_,
522
523
  authorizeKeys,
523
524
  calls,
@@ -530,6 +531,7 @@ export async function sendCalls<
530
531
  const signature = await Key.sign(key, {
531
532
  address: null,
532
533
  payload: digest,
534
+ typedData,
533
535
  webAuthn,
534
536
  })
535
537
  return { context, signature }
@@ -537,13 +539,16 @@ export async function sendCalls<
537
539
  )
538
540
 
539
541
  // Prepare main bundle.
540
- const { capabilities, context, digest } = await prepareCalls(client, {
541
- ...parameters,
542
- account: account_,
543
- chain,
544
- key,
545
- preCalls,
546
- } as never)
542
+ const { capabilities, context, digest, typedData } = await prepareCalls(
543
+ client,
544
+ {
545
+ ...parameters,
546
+ account: account_,
547
+ chain,
548
+ key,
549
+ preCalls,
550
+ } as never,
551
+ )
547
552
 
548
553
  // Sign over the bundles.
549
554
  const signature = await (async () => {
@@ -551,6 +556,7 @@ export async function sendCalls<
551
556
  return await Key.sign(key, {
552
557
  address: null,
553
558
  payload: digest,
559
+ typedData,
554
560
  webAuthn,
555
561
  wrap: false,
556
562
  })
@@ -630,6 +636,7 @@ export async function signCalls(
630
636
  key: keyIndex,
631
637
  payload: request.digest,
632
638
  replaySafe: false,
639
+ typedData: request.typedData,
633
640
  wrap: isPrecall,
634
641
  })
635
642
  }
@@ -637,6 +644,7 @@ export async function signCalls(
637
644
  return await Key.sign(key, {
638
645
  address: null,
639
646
  payload: request.digest,
647
+ typedData: request.typedData,
640
648
  wrap: isPrecall,
641
649
  })
642
650
  throw new Error('no key or account provided')
@@ -928,6 +936,19 @@ export type Decorator<
928
936
  createAccount: (
929
937
  parameters: createAccount.Parameters<chain>,
930
938
  ) => Promise<createAccount.ReturnType>
939
+ /**
940
+ * Gets an account by key hash.
941
+ *
942
+ * @example
943
+ * TODO
944
+ *
945
+ * @param client - The client to use.
946
+ * @param parameters - Parameters.
947
+ * @returns Result.
948
+ */
949
+ getAccount: (
950
+ parameters: RelayActions.getAccount.Parameters,
951
+ ) => Promise<RelayActions.getAccount.ReturnType>
931
952
  /**
932
953
  * Gets the status of a call bundle.
933
954
  *
@@ -1065,6 +1086,7 @@ export function decorator<
1065
1086
  >(client: Client<transport, chain, account>): Decorator<chain, account> {
1066
1087
  return {
1067
1088
  createAccount: (parameters) => createAccount(client, parameters),
1089
+ getAccount: (parameters) => RelayActions.getAccount(client, parameters),
1068
1090
  getCallsStatus: (parameters) =>
1069
1091
  RelayActions.getCallsStatus(client, parameters),
1070
1092
  getCapabilities: () => RelayActions.getCapabilities(client),
@@ -0,0 +1,19 @@
1
+ import * as Mipd from 'mipd'
2
+ import * as MipdPostMessage from 'mipd-postmessage/child'
3
+
4
+ const mipdPMStore = MipdPostMessage.createStore()
5
+ const mipdStore = Mipd.createStore()
6
+
7
+ export async function getProvider(parameters: { rdns: string }) {
8
+ const parentProviders = mipdPMStore
9
+ .getProviders()
10
+ .filter((p) => p.info.rdns !== 'com.risechain.wallet')
11
+ const providers = mipdStore
12
+ .getProviders()
13
+ .filter((p) => p.info.rdns !== 'com.risechain.wallet')
14
+
15
+ return (
16
+ providers.find((p) => p.info.rdns === parameters.rdns) ??
17
+ parentProviders.find((p) => p.info.rdns === parameters.rdns)
18
+ )
19
+ }
@@ -308,6 +308,48 @@ export namespace getCallsStatus {
308
308
  export type ErrorType = parseSchemaError.ErrorType | Errors.GlobalErrorType
309
309
  }
310
310
 
311
+ /**
312
+ * Gets an account by key hash.
313
+ *
314
+ * @example
315
+ * TODO
316
+ *
317
+ * @param client - The client to use.
318
+ * @param parameters - Parameters.
319
+ * @returns Result.
320
+ */
321
+ export async function getAccount(
322
+ client: Client,
323
+ parameters: getAccount.Parameters,
324
+ ): Promise<getAccount.ReturnType> {
325
+ const { keyHash } = parameters
326
+
327
+ try {
328
+ const method = 'wallet_getAccount' as const
329
+ type Schema = Extract<RpcSchema.Viem[number], { Method: typeof method }>
330
+ const result = await client.request<Schema>({
331
+ method,
332
+ params: [
333
+ z.encode(RpcSchema.wallet_getAccount.Parameters, {
334
+ keyHash,
335
+ }),
336
+ ],
337
+ })
338
+ return z.decode(RpcSchema.wallet_getAccount.Response, result)
339
+ } catch (error) {
340
+ parseSchemaError(error)
341
+ throw error
342
+ }
343
+ }
344
+
345
+ export namespace getAccount {
346
+ export type Parameters = RpcSchema.wallet_getAccount.Parameters
347
+
348
+ export type ReturnType = RpcSchema.wallet_getAccount.Response
349
+
350
+ export type ErrorType = parseSchemaError.ErrorType | Errors.GlobalErrorType
351
+ }
352
+
311
353
  /**
312
354
  * Gets the keys for a given account.
313
355
  *