@0xsequence/guard 1.4.9 → 1.5.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.
|
@@ -215,15 +215,10 @@ class GuardSigner {
|
|
|
215
215
|
async decorateTransactions(bundle, _metadata) {
|
|
216
216
|
return bundle;
|
|
217
217
|
}
|
|
218
|
-
async
|
|
218
|
+
async sign(message, metadata) {
|
|
219
219
|
var _metadata$parts;
|
|
220
|
-
const {
|
|
221
|
-
onSignature,
|
|
222
|
-
onRejection
|
|
223
|
-
} = callbacks;
|
|
224
220
|
if (!core.commons.isWalletSignRequestMetadata(metadata)) {
|
|
225
|
-
|
|
226
|
-
return false;
|
|
221
|
+
throw new Error('expected sequence signature request metadata');
|
|
227
222
|
}
|
|
228
223
|
const guardTotpCode = metadata.guardTotpCode;
|
|
229
224
|
|
|
@@ -233,31 +228,18 @@ class GuardSigner {
|
|
|
233
228
|
const {
|
|
234
229
|
encoded
|
|
235
230
|
} = coder.signature.encodeSigners(metadata.config, (_metadata$parts = metadata.parts) != null ? _metadata$parts : new Map(), [], metadata.chainId);
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
token: guardTotpCode
|
|
249
|
-
} : undefined
|
|
250
|
-
});
|
|
251
|
-
if (ethers.ethers.utils.arrayify(signature).length === 0) {
|
|
252
|
-
throw new Error('guard response contained no signature data');
|
|
253
|
-
}
|
|
254
|
-
onSignature(signature);
|
|
255
|
-
return true;
|
|
256
|
-
} catch (error) {
|
|
257
|
-
var _ref, _error$message;
|
|
258
|
-
onRejection(`unable to request guard signature: ${(_ref = (_error$message = error.message) != null ? _error$message : error.msg) != null ? _ref : error}`);
|
|
259
|
-
return false;
|
|
260
|
-
}
|
|
231
|
+
return (await this.guard.signWith({
|
|
232
|
+
signer: this.address,
|
|
233
|
+
request: {
|
|
234
|
+
msg: ethers.ethers.utils.hexlify(message),
|
|
235
|
+
auxData: this.packMsgAndSig(metadata.address, metadata.digest, encoded, metadata.chainId),
|
|
236
|
+
chainId: ethers.ethers.BigNumber.from(metadata.chainId).toNumber()
|
|
237
|
+
},
|
|
238
|
+
token: guardTotpCode ? {
|
|
239
|
+
id: AuthMethod.TOTP,
|
|
240
|
+
token: guardTotpCode
|
|
241
|
+
} : undefined
|
|
242
|
+
})).sig;
|
|
261
243
|
}
|
|
262
244
|
notifyStatusChange(_id, _status, _metadata) {}
|
|
263
245
|
async getAuthMethods(proof) {
|
|
@@ -411,19 +393,12 @@ async function signOwnershipProof(proof) {
|
|
|
411
393
|
const timestamp = new Date();
|
|
412
394
|
const typedData = getOwnershipProofTypedData(proof.walletAddress, timestamp);
|
|
413
395
|
const digest = utils.encodeTypedDataDigest(typedData);
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
signerAddress,
|
|
421
|
-
signature: ethers.ethers.utils.hexlify(signature)
|
|
422
|
-
});
|
|
423
|
-
},
|
|
424
|
-
onRejection: reject,
|
|
425
|
-
onStatus(_situation) {}
|
|
426
|
-
}));
|
|
396
|
+
return {
|
|
397
|
+
walletAddress: proof.walletAddress,
|
|
398
|
+
timestamp,
|
|
399
|
+
signerAddress,
|
|
400
|
+
signature: ethers.ethers.utils.hexlify(await signer.sign(digest, {}))
|
|
401
|
+
};
|
|
427
402
|
}
|
|
428
403
|
}
|
|
429
404
|
async function signAuthUpdateProof(proof) {
|
|
@@ -215,15 +215,10 @@ class GuardSigner {
|
|
|
215
215
|
async decorateTransactions(bundle, _metadata) {
|
|
216
216
|
return bundle;
|
|
217
217
|
}
|
|
218
|
-
async
|
|
218
|
+
async sign(message, metadata) {
|
|
219
219
|
var _metadata$parts;
|
|
220
|
-
const {
|
|
221
|
-
onSignature,
|
|
222
|
-
onRejection
|
|
223
|
-
} = callbacks;
|
|
224
220
|
if (!core.commons.isWalletSignRequestMetadata(metadata)) {
|
|
225
|
-
|
|
226
|
-
return false;
|
|
221
|
+
throw new Error('expected sequence signature request metadata');
|
|
227
222
|
}
|
|
228
223
|
const guardTotpCode = metadata.guardTotpCode;
|
|
229
224
|
|
|
@@ -233,31 +228,18 @@ class GuardSigner {
|
|
|
233
228
|
const {
|
|
234
229
|
encoded
|
|
235
230
|
} = coder.signature.encodeSigners(metadata.config, (_metadata$parts = metadata.parts) != null ? _metadata$parts : new Map(), [], metadata.chainId);
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
token: guardTotpCode
|
|
249
|
-
} : undefined
|
|
250
|
-
});
|
|
251
|
-
if (ethers.ethers.utils.arrayify(signature).length === 0) {
|
|
252
|
-
throw new Error('guard response contained no signature data');
|
|
253
|
-
}
|
|
254
|
-
onSignature(signature);
|
|
255
|
-
return true;
|
|
256
|
-
} catch (error) {
|
|
257
|
-
var _ref, _error$message;
|
|
258
|
-
onRejection(`unable to request guard signature: ${(_ref = (_error$message = error.message) != null ? _error$message : error.msg) != null ? _ref : error}`);
|
|
259
|
-
return false;
|
|
260
|
-
}
|
|
231
|
+
return (await this.guard.signWith({
|
|
232
|
+
signer: this.address,
|
|
233
|
+
request: {
|
|
234
|
+
msg: ethers.ethers.utils.hexlify(message),
|
|
235
|
+
auxData: this.packMsgAndSig(metadata.address, metadata.digest, encoded, metadata.chainId),
|
|
236
|
+
chainId: ethers.ethers.BigNumber.from(metadata.chainId).toNumber()
|
|
237
|
+
},
|
|
238
|
+
token: guardTotpCode ? {
|
|
239
|
+
id: AuthMethod.TOTP,
|
|
240
|
+
token: guardTotpCode
|
|
241
|
+
} : undefined
|
|
242
|
+
})).sig;
|
|
261
243
|
}
|
|
262
244
|
notifyStatusChange(_id, _status, _metadata) {}
|
|
263
245
|
async getAuthMethods(proof) {
|
|
@@ -411,19 +393,12 @@ async function signOwnershipProof(proof) {
|
|
|
411
393
|
const timestamp = new Date();
|
|
412
394
|
const typedData = getOwnershipProofTypedData(proof.walletAddress, timestamp);
|
|
413
395
|
const digest = utils.encodeTypedDataDigest(typedData);
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
signerAddress,
|
|
421
|
-
signature: ethers.ethers.utils.hexlify(signature)
|
|
422
|
-
});
|
|
423
|
-
},
|
|
424
|
-
onRejection: reject,
|
|
425
|
-
onStatus(_situation) {}
|
|
426
|
-
}));
|
|
396
|
+
return {
|
|
397
|
+
walletAddress: proof.walletAddress,
|
|
398
|
+
timestamp,
|
|
399
|
+
signerAddress,
|
|
400
|
+
signature: ethers.ethers.utils.hexlify(await signer.sign(digest, {}))
|
|
401
|
+
};
|
|
427
402
|
}
|
|
428
403
|
}
|
|
429
404
|
async function signAuthUpdateProof(proof) {
|
|
@@ -211,15 +211,10 @@ class GuardSigner {
|
|
|
211
211
|
async decorateTransactions(bundle, _metadata) {
|
|
212
212
|
return bundle;
|
|
213
213
|
}
|
|
214
|
-
async
|
|
214
|
+
async sign(message, metadata) {
|
|
215
215
|
var _metadata$parts;
|
|
216
|
-
const {
|
|
217
|
-
onSignature,
|
|
218
|
-
onRejection
|
|
219
|
-
} = callbacks;
|
|
220
216
|
if (!commons.isWalletSignRequestMetadata(metadata)) {
|
|
221
|
-
|
|
222
|
-
return false;
|
|
217
|
+
throw new Error('expected sequence signature request metadata');
|
|
223
218
|
}
|
|
224
219
|
const guardTotpCode = metadata.guardTotpCode;
|
|
225
220
|
|
|
@@ -229,31 +224,18 @@ class GuardSigner {
|
|
|
229
224
|
const {
|
|
230
225
|
encoded
|
|
231
226
|
} = coder.signature.encodeSigners(metadata.config, (_metadata$parts = metadata.parts) != null ? _metadata$parts : new Map(), [], metadata.chainId);
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
token: guardTotpCode
|
|
245
|
-
} : undefined
|
|
246
|
-
});
|
|
247
|
-
if (ethers.utils.arrayify(signature).length === 0) {
|
|
248
|
-
throw new Error('guard response contained no signature data');
|
|
249
|
-
}
|
|
250
|
-
onSignature(signature);
|
|
251
|
-
return true;
|
|
252
|
-
} catch (error) {
|
|
253
|
-
var _ref, _error$message;
|
|
254
|
-
onRejection(`unable to request guard signature: ${(_ref = (_error$message = error.message) != null ? _error$message : error.msg) != null ? _ref : error}`);
|
|
255
|
-
return false;
|
|
256
|
-
}
|
|
227
|
+
return (await this.guard.signWith({
|
|
228
|
+
signer: this.address,
|
|
229
|
+
request: {
|
|
230
|
+
msg: ethers.utils.hexlify(message),
|
|
231
|
+
auxData: this.packMsgAndSig(metadata.address, metadata.digest, encoded, metadata.chainId),
|
|
232
|
+
chainId: ethers.BigNumber.from(metadata.chainId).toNumber()
|
|
233
|
+
},
|
|
234
|
+
token: guardTotpCode ? {
|
|
235
|
+
id: AuthMethod.TOTP,
|
|
236
|
+
token: guardTotpCode
|
|
237
|
+
} : undefined
|
|
238
|
+
})).sig;
|
|
257
239
|
}
|
|
258
240
|
notifyStatusChange(_id, _status, _metadata) {}
|
|
259
241
|
async getAuthMethods(proof) {
|
|
@@ -407,19 +389,12 @@ async function signOwnershipProof(proof) {
|
|
|
407
389
|
const timestamp = new Date();
|
|
408
390
|
const typedData = getOwnershipProofTypedData(proof.walletAddress, timestamp);
|
|
409
391
|
const digest = encodeTypedDataDigest(typedData);
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
signerAddress,
|
|
417
|
-
signature: ethers.utils.hexlify(signature)
|
|
418
|
-
});
|
|
419
|
-
},
|
|
420
|
-
onRejection: reject,
|
|
421
|
-
onStatus(_situation) {}
|
|
422
|
-
}));
|
|
392
|
+
return {
|
|
393
|
+
walletAddress: proof.walletAddress,
|
|
394
|
+
timestamp,
|
|
395
|
+
signerAddress,
|
|
396
|
+
signature: ethers.utils.hexlify(await signer.sign(digest, {}))
|
|
397
|
+
};
|
|
423
398
|
}
|
|
424
399
|
}
|
|
425
400
|
async function signAuthUpdateProof(proof) {
|
|
@@ -14,11 +14,7 @@ export declare class GuardSigner implements signers.SapientSigner {
|
|
|
14
14
|
buildDeployTransaction(_metadata: object): Promise<commons.transaction.TransactionBundle | undefined>;
|
|
15
15
|
predecorateSignedTransactions(_metadata: object): Promise<commons.transaction.SignedTransactionBundle[]>;
|
|
16
16
|
decorateTransactions(bundle: commons.transaction.IntendedTransactionBundle, _metadata: object): Promise<commons.transaction.IntendedTransactionBundle>;
|
|
17
|
-
|
|
18
|
-
onSignature: (signature: BytesLike) => void;
|
|
19
|
-
onRejection: (error: string) => void;
|
|
20
|
-
onStatus: (situation: string) => void;
|
|
21
|
-
}): Promise<boolean>;
|
|
17
|
+
sign(message: BytesLike, metadata: object): Promise<BytesLike>;
|
|
22
18
|
notifyStatusChange(_id: string, _status: Status, _metadata: object): void;
|
|
23
19
|
getAuthMethods(proof: OwnershipProof): Promise<{
|
|
24
20
|
methods: AuthMethod[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/guard",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "guard sub-package for Sequence",
|
|
5
5
|
"repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/guard",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"ethers": "^5.7.2",
|
|
13
|
-
"@0xsequence/
|
|
14
|
-
"@0xsequence/core": "1.
|
|
15
|
-
"@0xsequence/
|
|
16
|
-
"@0xsequence/
|
|
13
|
+
"@0xsequence/account": "1.5.0",
|
|
14
|
+
"@0xsequence/core": "1.5.0",
|
|
15
|
+
"@0xsequence/signhub": "1.5.0",
|
|
16
|
+
"@0xsequence/utils": "1.5.0"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"src",
|
package/src/signer.ts
CHANGED
|
@@ -37,21 +37,9 @@ export class GuardSigner implements signers.SapientSigner {
|
|
|
37
37
|
return bundle
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
async
|
|
41
|
-
_id: string,
|
|
42
|
-
message: BytesLike,
|
|
43
|
-
metadata: object,
|
|
44
|
-
callbacks: {
|
|
45
|
-
onSignature: (signature: BytesLike) => void
|
|
46
|
-
onRejection: (error: string) => void
|
|
47
|
-
onStatus: (situation: string) => void
|
|
48
|
-
}
|
|
49
|
-
): Promise<boolean> {
|
|
50
|
-
const { onSignature, onRejection } = callbacks
|
|
51
|
-
|
|
40
|
+
async sign(message: BytesLike, metadata: object): Promise<BytesLike> {
|
|
52
41
|
if (!commons.isWalletSignRequestMetadata(metadata)) {
|
|
53
|
-
|
|
54
|
-
return false
|
|
42
|
+
throw new Error('expected sequence signature request metadata')
|
|
55
43
|
}
|
|
56
44
|
|
|
57
45
|
const guardTotpCode = (metadata as { guardTotpCode?: string }).guardTotpCode
|
|
@@ -61,8 +49,8 @@ export class GuardSigner implements signers.SapientSigner {
|
|
|
61
49
|
const coder = universal.genericCoderFor(metadata.config.version)
|
|
62
50
|
const { encoded } = coder.signature.encodeSigners(metadata.config, metadata.parts ?? new Map(), [], metadata.chainId)
|
|
63
51
|
|
|
64
|
-
|
|
65
|
-
|
|
52
|
+
return (
|
|
53
|
+
await this.guard.signWith({
|
|
66
54
|
signer: this.address,
|
|
67
55
|
request: {
|
|
68
56
|
msg: ethers.utils.hexlify(message),
|
|
@@ -71,17 +59,7 @@ export class GuardSigner implements signers.SapientSigner {
|
|
|
71
59
|
},
|
|
72
60
|
token: guardTotpCode ? { id: AuthMethod.TOTP, token: guardTotpCode } : undefined
|
|
73
61
|
})
|
|
74
|
-
|
|
75
|
-
if (ethers.utils.arrayify(signature).length === 0) {
|
|
76
|
-
throw new Error('guard response contained no signature data')
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
onSignature(signature)
|
|
80
|
-
return true
|
|
81
|
-
} catch (error) {
|
|
82
|
-
onRejection(`unable to request guard signature: ${error.message ?? error.msg ?? error}`)
|
|
83
|
-
return false
|
|
84
|
-
}
|
|
62
|
+
).sig
|
|
85
63
|
}
|
|
86
64
|
|
|
87
65
|
notifyStatusChange(_id: string, _status: Status, _metadata: object): void {}
|
|
@@ -248,27 +226,13 @@ async function signOwnershipProof(
|
|
|
248
226
|
const timestamp = new Date()
|
|
249
227
|
const typedData = getOwnershipProofTypedData(proof.walletAddress, timestamp)
|
|
250
228
|
const digest = encodeTypedDataDigest(typedData)
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
{
|
|
259
|
-
onSignature(signature) {
|
|
260
|
-
resolve({
|
|
261
|
-
walletAddress: proof.walletAddress,
|
|
262
|
-
timestamp,
|
|
263
|
-
signerAddress,
|
|
264
|
-
signature: ethers.utils.hexlify(signature)
|
|
265
|
-
})
|
|
266
|
-
},
|
|
267
|
-
onRejection: reject,
|
|
268
|
-
onStatus(_situation) {}
|
|
269
|
-
}
|
|
270
|
-
)
|
|
271
|
-
)
|
|
229
|
+
|
|
230
|
+
return {
|
|
231
|
+
walletAddress: proof.walletAddress,
|
|
232
|
+
timestamp,
|
|
233
|
+
signerAddress,
|
|
234
|
+
signature: ethers.utils.hexlify(await signer.sign(digest, {}))
|
|
235
|
+
}
|
|
272
236
|
}
|
|
273
237
|
}
|
|
274
238
|
|