@0xsequence/guard 1.0.3 → 1.0.5
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/0xsequence-guard.cjs.d.ts +1 -0
- package/dist/0xsequence-guard.cjs.d.ts.map +1 -0
- package/dist/0xsequence-guard.cjs.dev.js +2 -1
- package/dist/0xsequence-guard.cjs.prod.js +2 -1
- package/dist/0xsequence-guard.esm.js +2 -1
- package/dist/declarations/src/index.d.ts +2 -2
- package/package.json +3 -3
- package/src/signer.ts +27 -32
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"0xsequence-guard.cjs.d.ts","sourceRoot":"","sources":["./declarations/src/index.d.ts"],"names":[],"mappings":"AAAA"}
|
|
@@ -135,13 +135,14 @@ const buildResponse = res => {
|
|
|
135
135
|
});
|
|
136
136
|
};
|
|
137
137
|
|
|
138
|
+
const fetch = typeof global === 'object' ? global.fetch : window.fetch;
|
|
138
139
|
class GuardSigner {
|
|
139
140
|
constructor(address, url, appendSuffix = false) {
|
|
140
141
|
this.requests = new Map();
|
|
141
142
|
this.address = address;
|
|
142
143
|
this.url = url;
|
|
143
144
|
this.appendSuffix = appendSuffix;
|
|
144
|
-
this.guard = new Guard(url,
|
|
145
|
+
this.guard = new Guard(url, fetch);
|
|
145
146
|
}
|
|
146
147
|
async getAddress() {
|
|
147
148
|
return this.address;
|
|
@@ -135,13 +135,14 @@ const buildResponse = res => {
|
|
|
135
135
|
});
|
|
136
136
|
};
|
|
137
137
|
|
|
138
|
+
const fetch = typeof global === 'object' ? global.fetch : window.fetch;
|
|
138
139
|
class GuardSigner {
|
|
139
140
|
constructor(address, url, appendSuffix = false) {
|
|
140
141
|
this.requests = new Map();
|
|
141
142
|
this.address = address;
|
|
142
143
|
this.url = url;
|
|
143
144
|
this.appendSuffix = appendSuffix;
|
|
144
|
-
this.guard = new Guard(url,
|
|
145
|
+
this.guard = new Guard(url, fetch);
|
|
145
146
|
}
|
|
146
147
|
async getAddress() {
|
|
147
148
|
return this.address;
|
|
@@ -131,13 +131,14 @@ const buildResponse = res => {
|
|
|
131
131
|
});
|
|
132
132
|
};
|
|
133
133
|
|
|
134
|
+
const fetch = typeof global === 'object' ? global.fetch : window.fetch;
|
|
134
135
|
class GuardSigner {
|
|
135
136
|
constructor(address, url, appendSuffix = false) {
|
|
136
137
|
this.requests = new Map();
|
|
137
138
|
this.address = address;
|
|
138
139
|
this.url = url;
|
|
139
140
|
this.appendSuffix = appendSuffix;
|
|
140
|
-
this.guard = new Guard(url,
|
|
141
|
+
this.guard = new Guard(url, fetch);
|
|
141
142
|
}
|
|
142
143
|
async getAddress() {
|
|
143
144
|
return this.address;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./guard.gen.js";
|
|
2
|
+
export * from "./signer.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/guard",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
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,8 +10,8 @@
|
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"ethers": "^5.7.2",
|
|
13
|
-
"@0xsequence/
|
|
14
|
-
"@0xsequence/
|
|
13
|
+
"@0xsequence/signhub": "1.0.5",
|
|
14
|
+
"@0xsequence/core": "1.0.5"
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"src",
|
package/src/signer.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
|
|
2
1
|
import { signers, Status } from '@0xsequence/signhub'
|
|
3
2
|
import { BytesLike, ethers } from 'ethers'
|
|
4
3
|
import { Guard } from './guard.gen'
|
|
5
4
|
import { commons, universal } from '@0xsequence/core'
|
|
6
5
|
|
|
6
|
+
const fetch = typeof global === 'object' ? global.fetch : window.fetch
|
|
7
|
+
|
|
7
8
|
export class GuardSigner implements signers.SapientSigner {
|
|
8
9
|
private guard: Guard
|
|
9
|
-
private requests: Map<
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.guard = new Guard(url, global.fetch)
|
|
10
|
+
private requests: Map<
|
|
11
|
+
string,
|
|
12
|
+
{
|
|
13
|
+
lastAttempt?: string
|
|
14
|
+
onSignature: (signature: BytesLike) => void
|
|
15
|
+
onRejection: (error: string) => void
|
|
16
|
+
onStatus: (situation: string) => void
|
|
17
|
+
}
|
|
18
|
+
> = new Map()
|
|
19
|
+
|
|
20
|
+
constructor(public readonly address: string, public readonly url: string, public readonly appendSuffix: boolean = false) {
|
|
21
|
+
this.guard = new Guard(url, fetch)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
async getAddress(): Promise<string> {
|
|
@@ -30,9 +30,9 @@ export class GuardSigner implements signers.SapientSigner {
|
|
|
30
30
|
_message: BytesLike,
|
|
31
31
|
metadata: Object,
|
|
32
32
|
callbacks: {
|
|
33
|
-
onSignature: (signature: BytesLike) => void
|
|
34
|
-
onRejection: (error: string) => void
|
|
35
|
-
onStatus: (situation: string) => void
|
|
33
|
+
onSignature: (signature: BytesLike) => void
|
|
34
|
+
onRejection: (error: string) => void
|
|
35
|
+
onStatus: (situation: string) => void
|
|
36
36
|
}
|
|
37
37
|
): Promise<boolean> {
|
|
38
38
|
if (!commons.isWalletSignRequestMetadata(metadata)) {
|
|
@@ -46,11 +46,7 @@ export class GuardSigner implements signers.SapientSigner {
|
|
|
46
46
|
return true
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
notifyStatusChange(
|
|
50
|
-
id: string,
|
|
51
|
-
status: Status,
|
|
52
|
-
metadata: Object
|
|
53
|
-
): void {
|
|
49
|
+
notifyStatusChange(id: string, status: Status, metadata: Object): void {
|
|
54
50
|
if (!this.requests.has(id)) return
|
|
55
51
|
|
|
56
52
|
if (!commons.isWalletSignRequestMetadata(metadata)) {
|
|
@@ -62,20 +58,19 @@ export class GuardSigner implements signers.SapientSigner {
|
|
|
62
58
|
}
|
|
63
59
|
|
|
64
60
|
private packMsgAndSig(address: string, msg: BytesLike, sig: BytesLike, chainId: ethers.BigNumberish): string {
|
|
65
|
-
return ethers.utils.defaultAbiCoder.encode(
|
|
66
|
-
['address', 'uint256', 'bytes', 'bytes'],
|
|
67
|
-
[address, chainId, msg, sig]
|
|
68
|
-
)
|
|
61
|
+
return ethers.utils.defaultAbiCoder.encode(['address', 'uint256', 'bytes', 'bytes'], [address, chainId, msg, sig])
|
|
69
62
|
}
|
|
70
63
|
|
|
71
64
|
private keyOfRequest(signer: string, msg: BytesLike, auxData: BytesLike, chainId: ethers.BigNumberish): string {
|
|
72
|
-
return ethers.utils.solidityKeccak256(
|
|
73
|
-
['address', 'uint256', 'bytes', 'bytes'],
|
|
74
|
-
[signer, chainId, msg, auxData]
|
|
75
|
-
)
|
|
65
|
+
return ethers.utils.solidityKeccak256(['address', 'uint256', 'bytes', 'bytes'], [signer, chainId, msg, auxData])
|
|
76
66
|
}
|
|
77
67
|
|
|
78
|
-
private async evaluateRequest(
|
|
68
|
+
private async evaluateRequest(
|
|
69
|
+
id: string,
|
|
70
|
+
message: BytesLike,
|
|
71
|
+
_: Status,
|
|
72
|
+
metadata: commons.WalletSignRequestMetadata
|
|
73
|
+
): Promise<void> {
|
|
79
74
|
// Building auxData, notice: this uses the old v1 format
|
|
80
75
|
// TODO: We should update the guard API so we can pass the metadata directly
|
|
81
76
|
const coder = universal.genericCoderFor(metadata.config.version)
|
|
@@ -112,6 +107,6 @@ export class GuardSigner implements signers.SapientSigner {
|
|
|
112
107
|
}
|
|
113
108
|
|
|
114
109
|
suffix(): BytesLike {
|
|
115
|
-
return this.appendSuffix ? [
|
|
110
|
+
return this.appendSuffix ? [3] : []
|
|
116
111
|
}
|
|
117
112
|
}
|