@portal-hq/web 1.0.3 → 2.0.0
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 +36 -0
- package/lib/commonjs/index.js +28 -18
- package/lib/commonjs/mpc/index.js +56 -10
- package/lib/commonjs/provider/index.js +18 -11
- package/lib/esm/index.js +28 -18
- package/lib/esm/mpc/index.js +56 -10
- package/lib/esm/provider/index.js +18 -11
- package/package.json +1 -1
- package/src/index.ts +51 -19
- package/src/mpc/index.ts +76 -13
- package/src/provider/index.ts +22 -10
- package/types.d.ts +42 -8
package/src/provider/index.ts
CHANGED
|
@@ -113,19 +113,27 @@ class Provider {
|
|
|
113
113
|
* @param args The arguments of the request being made
|
|
114
114
|
* @returns Promise<any>
|
|
115
115
|
*/
|
|
116
|
-
public async request({
|
|
116
|
+
public async request({
|
|
117
|
+
chainId,
|
|
118
|
+
method,
|
|
119
|
+
params,
|
|
120
|
+
}: RequestArguments): Promise<any> {
|
|
117
121
|
if (method === 'eth_chainId') {
|
|
118
|
-
return this.portal.chainId
|
|
122
|
+
return chainId ? parseInt(chainId.split(':')[1]) : this.portal.chainId
|
|
119
123
|
}
|
|
120
124
|
|
|
121
125
|
const isSignerMethod = signerMethods.includes(method)
|
|
122
126
|
|
|
123
|
-
let result: any
|
|
124
127
|
if (!isSignerMethod && !method.startsWith('wallet_')) {
|
|
125
128
|
// Send to Gateway for RPC calls
|
|
126
|
-
const response = await this.handleGatewayRequest({
|
|
129
|
+
const response = await this.handleGatewayRequest({
|
|
130
|
+
chainId,
|
|
131
|
+
method,
|
|
132
|
+
params,
|
|
133
|
+
})
|
|
127
134
|
|
|
128
135
|
this.emit('portal_signatureReceived', {
|
|
136
|
+
chainId,
|
|
129
137
|
method,
|
|
130
138
|
params,
|
|
131
139
|
signature: response,
|
|
@@ -135,22 +143,24 @@ class Provider {
|
|
|
135
143
|
throw new ProviderRpcError(response.error as RpcErrorOptions)
|
|
136
144
|
}
|
|
137
145
|
|
|
138
|
-
|
|
146
|
+
return response.result
|
|
139
147
|
} else if (isSignerMethod) {
|
|
140
148
|
// Handle signing
|
|
141
149
|
const transactionHash = await this.handleSigningRequest({
|
|
150
|
+
chainId,
|
|
142
151
|
method,
|
|
143
152
|
params,
|
|
144
153
|
})
|
|
145
154
|
|
|
146
155
|
if (transactionHash) {
|
|
147
156
|
this.emit('portal_signatureReceived', {
|
|
157
|
+
chainId,
|
|
148
158
|
method,
|
|
149
159
|
params,
|
|
150
160
|
signature: transactionHash,
|
|
151
161
|
})
|
|
152
162
|
|
|
153
|
-
|
|
163
|
+
return transactionHash
|
|
154
164
|
}
|
|
155
165
|
} else {
|
|
156
166
|
// Unsupported method
|
|
@@ -162,8 +172,6 @@ class Provider {
|
|
|
162
172
|
},
|
|
163
173
|
})
|
|
164
174
|
}
|
|
165
|
-
|
|
166
|
-
return result
|
|
167
175
|
}
|
|
168
176
|
|
|
169
177
|
/************************
|
|
@@ -252,6 +260,7 @@ class Provider {
|
|
|
252
260
|
* @returns Promise<any>
|
|
253
261
|
*/
|
|
254
262
|
private async handleGatewayRequest({
|
|
263
|
+
chainId,
|
|
255
264
|
method,
|
|
256
265
|
params,
|
|
257
266
|
}: RequestArguments): Promise<any> {
|
|
@@ -259,7 +268,7 @@ class Provider {
|
|
|
259
268
|
const result = await fetch(this.portal.getRpcUrl(), {
|
|
260
269
|
body: JSON.stringify({
|
|
261
270
|
jsonrpc: '2.0',
|
|
262
|
-
id: this.portal.chainId,
|
|
271
|
+
id: chainId ? parseInt(chainId.split(':')[1]) : this.portal.chainId,
|
|
263
272
|
method,
|
|
264
273
|
params,
|
|
265
274
|
}),
|
|
@@ -276,6 +285,7 @@ class Provider {
|
|
|
276
285
|
* @returns Promise<any>
|
|
277
286
|
*/
|
|
278
287
|
private async handleSigningRequest({
|
|
288
|
+
chainId,
|
|
279
289
|
method,
|
|
280
290
|
params,
|
|
281
291
|
}: RequestArguments): Promise<any> {
|
|
@@ -303,7 +313,9 @@ class Provider {
|
|
|
303
313
|
case 'eth_signTypedData_v4':
|
|
304
314
|
case 'personal_sign': {
|
|
305
315
|
const result = await this.portal.mpc.sign({
|
|
306
|
-
chainId:
|
|
316
|
+
chainId: chainId
|
|
317
|
+
? chainId.split(':')[1]
|
|
318
|
+
: this.portal.chainId.toString(),
|
|
307
319
|
method,
|
|
308
320
|
params: this.buildParams(method, params),
|
|
309
321
|
rpcUrl: this.portal.getRpcUrl(),
|
package/types.d.ts
CHANGED
|
@@ -62,8 +62,8 @@ export interface BackupData {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export interface BackupResult {
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
backupIds: string[]
|
|
66
|
+
cipherText: string
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
export interface Bk {
|
|
@@ -77,20 +77,53 @@ export interface Address {
|
|
|
77
77
|
value: string
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
export interface BackupResponse {
|
|
81
|
+
cipherText: string
|
|
82
|
+
storageCallback: () => Promise<void>
|
|
83
|
+
}
|
|
84
|
+
|
|
80
85
|
export interface Balance {
|
|
81
86
|
contractAddress: string
|
|
82
87
|
balance: string
|
|
83
88
|
}
|
|
84
89
|
|
|
85
|
-
export interface
|
|
90
|
+
export interface ClientResponse {
|
|
86
91
|
id: string
|
|
87
92
|
address: string
|
|
88
93
|
backupStatus?: string | null
|
|
89
|
-
custodian:
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
custodian: ClientResponseCustodian
|
|
95
|
+
ejectedAt: string | null
|
|
96
|
+
isAccountAbstracted: boolean
|
|
97
|
+
metadata: ClientResponseMetadata
|
|
98
|
+
wallets: ClientResponseWallet[]
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
interface ClientResponseCustodian {
|
|
102
|
+
id: string
|
|
103
|
+
name: string
|
|
104
|
+
}
|
|
105
|
+
interface ClientResponseMetadata {
|
|
106
|
+
namespaces: ClientNamespaceMetadata
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface ClientResponseNamespaceMetadata {
|
|
110
|
+
[key: Namespace]: NamespaceMetadataItem
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
interface ClientResponseSharePair {
|
|
114
|
+
id: string
|
|
115
|
+
createdAt: string
|
|
116
|
+
status: SharePairStatus
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface ClientResponseWallet {
|
|
120
|
+
id: string
|
|
121
|
+
createdAt: string
|
|
122
|
+
|
|
123
|
+
backupSharePairs: ClientResponseSharePair[]
|
|
124
|
+
curve: WalletCurve
|
|
125
|
+
publicKey: string
|
|
126
|
+
signingSharePairs: ClientResponseShairPair[]
|
|
94
127
|
}
|
|
95
128
|
|
|
96
129
|
export interface DappOnNetwork {
|
|
@@ -392,6 +425,7 @@ export interface RegisteredEventHandler {
|
|
|
392
425
|
}
|
|
393
426
|
|
|
394
427
|
export interface RequestArguments {
|
|
428
|
+
chainId?: string
|
|
395
429
|
method: string
|
|
396
430
|
params?: unknown[] | SigningRequestParams
|
|
397
431
|
}
|