@0xsequence/replacer 1.10.14 → 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/dist/0xsequence-replacer.cjs.dev.js +5 -3
- package/dist/0xsequence-replacer.cjs.prod.js +5 -3
- package/dist/0xsequence-replacer.esm.js +5 -3
- package/dist/declarations/src/cached.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +4 -4
- package/package.json +4 -4
- package/src/cached.ts +1 -1
- package/src/index.ts +9 -8
|
@@ -61,7 +61,7 @@ function eip1271Contract(address, provider) {
|
|
|
61
61
|
async function isValidSignature(address, provider, digest, signature) {
|
|
62
62
|
// First we try to validate the signature using Ethers
|
|
63
63
|
try {
|
|
64
|
-
const addr = ethers.ethers.
|
|
64
|
+
const addr = ethers.ethers.recoverAddress(digest, ethers.ethers.hexlify(signature));
|
|
65
65
|
if (addr.toLowerCase() === address.toLowerCase()) return true;
|
|
66
66
|
} catch (_unused) {}
|
|
67
67
|
|
|
@@ -95,9 +95,11 @@ async function runByEIP5719(address, provider, digest, signature, solver, tries
|
|
|
95
95
|
} catch (_unused4) {}
|
|
96
96
|
const altUri = await tryAwait(eip5719Contract(address, provider).getAlternativeSignature(digest));
|
|
97
97
|
if (!altUri || altUri === '') throw new Error('EIP5719 - Invalid signature and no alternative signature');
|
|
98
|
-
const altSignature = ethers.ethers.
|
|
98
|
+
const altSignature = ethers.ethers.hexlify(await (solver || new URISolverIPFS()).resolve(altUri));
|
|
99
99
|
if (!altSignature || altSignature === '') throw new Error('EIP5719 - Empty alternative signature');
|
|
100
|
-
if (altSignature === ethers.ethers.
|
|
100
|
+
if (altSignature === ethers.ethers.hexlify(signature)) {
|
|
101
|
+
throw new Error('EIP5719 - Alternative signature is invalid or the same');
|
|
102
|
+
}
|
|
101
103
|
return runByEIP5719(address, provider, digest, altSignature, solver, tries + 1);
|
|
102
104
|
}
|
|
103
105
|
class URISolverIPFS {
|
|
@@ -61,7 +61,7 @@ function eip1271Contract(address, provider) {
|
|
|
61
61
|
async function isValidSignature(address, provider, digest, signature) {
|
|
62
62
|
// First we try to validate the signature using Ethers
|
|
63
63
|
try {
|
|
64
|
-
const addr = ethers.ethers.
|
|
64
|
+
const addr = ethers.ethers.recoverAddress(digest, ethers.ethers.hexlify(signature));
|
|
65
65
|
if (addr.toLowerCase() === address.toLowerCase()) return true;
|
|
66
66
|
} catch (_unused) {}
|
|
67
67
|
|
|
@@ -95,9 +95,11 @@ async function runByEIP5719(address, provider, digest, signature, solver, tries
|
|
|
95
95
|
} catch (_unused4) {}
|
|
96
96
|
const altUri = await tryAwait(eip5719Contract(address, provider).getAlternativeSignature(digest));
|
|
97
97
|
if (!altUri || altUri === '') throw new Error('EIP5719 - Invalid signature and no alternative signature');
|
|
98
|
-
const altSignature = ethers.ethers.
|
|
98
|
+
const altSignature = ethers.ethers.hexlify(await (solver || new URISolverIPFS()).resolve(altUri));
|
|
99
99
|
if (!altSignature || altSignature === '') throw new Error('EIP5719 - Empty alternative signature');
|
|
100
|
-
if (altSignature === ethers.ethers.
|
|
100
|
+
if (altSignature === ethers.ethers.hexlify(signature)) {
|
|
101
|
+
throw new Error('EIP5719 - Alternative signature is invalid or the same');
|
|
102
|
+
}
|
|
101
103
|
return runByEIP5719(address, provider, digest, altSignature, solver, tries + 1);
|
|
102
104
|
}
|
|
103
105
|
class URISolverIPFS {
|
|
@@ -57,7 +57,7 @@ function eip1271Contract(address, provider) {
|
|
|
57
57
|
async function isValidSignature(address, provider, digest, signature) {
|
|
58
58
|
// First we try to validate the signature using Ethers
|
|
59
59
|
try {
|
|
60
|
-
const addr = ethers.
|
|
60
|
+
const addr = ethers.recoverAddress(digest, ethers.hexlify(signature));
|
|
61
61
|
if (addr.toLowerCase() === address.toLowerCase()) return true;
|
|
62
62
|
} catch (_unused) {}
|
|
63
63
|
|
|
@@ -91,9 +91,11 @@ async function runByEIP5719(address, provider, digest, signature, solver, tries
|
|
|
91
91
|
} catch (_unused4) {}
|
|
92
92
|
const altUri = await tryAwait(eip5719Contract(address, provider).getAlternativeSignature(digest));
|
|
93
93
|
if (!altUri || altUri === '') throw new Error('EIP5719 - Invalid signature and no alternative signature');
|
|
94
|
-
const altSignature = ethers.
|
|
94
|
+
const altSignature = ethers.hexlify(await (solver || new URISolverIPFS()).resolve(altUri));
|
|
95
95
|
if (!altSignature || altSignature === '') throw new Error('EIP5719 - Empty alternative signature');
|
|
96
|
-
if (altSignature === ethers.
|
|
96
|
+
if (altSignature === ethers.hexlify(signature)) {
|
|
97
|
+
throw new Error('EIP5719 - Alternative signature is invalid or the same');
|
|
98
|
+
}
|
|
97
99
|
return runByEIP5719(address, provider, digest, altSignature, solver, tries + 1);
|
|
98
100
|
}
|
|
99
101
|
class URISolverIPFS {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
2
|
import { URISolver } from "./index.js";
|
|
3
3
|
export declare class CachedEIP5719 {
|
|
4
|
-
provider: ethers.
|
|
4
|
+
provider: ethers.Provider;
|
|
5
5
|
solver?: URISolver | undefined;
|
|
6
6
|
window: number;
|
|
7
|
-
constructor(provider: ethers.
|
|
7
|
+
constructor(provider: ethers.Provider, solver?: URISolver | undefined, window?: number);
|
|
8
8
|
private pending;
|
|
9
9
|
runByEIP5719(address: string, digest: ethers.BytesLike, signature: ethers.BytesLike): Promise<ethers.BytesLike>;
|
|
10
10
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
2
|
export * from "./cached.js";
|
|
3
|
-
export declare function eip5719Contract(address: string, provider: ethers.
|
|
4
|
-
export declare function eip1271Contract(address: string, provider: ethers.
|
|
5
|
-
export declare function isValidSignature(address: string, provider: ethers.
|
|
3
|
+
export declare function eip5719Contract(address: string, provider: ethers.Provider): ethers.Contract;
|
|
4
|
+
export declare function eip1271Contract(address: string, provider: ethers.Provider): ethers.Contract;
|
|
5
|
+
export declare function isValidSignature(address: string, provider: ethers.Provider, digest: ethers.BytesLike, signature: ethers.BytesLike): Promise<boolean>;
|
|
6
6
|
export interface URISolver {
|
|
7
7
|
resolve: (uri: string) => Promise<string>;
|
|
8
8
|
}
|
|
9
|
-
export declare function runByEIP5719(address: string, provider: ethers.
|
|
9
|
+
export declare function runByEIP5719(address: string, provider: ethers.Provider, digest: ethers.BytesLike, signature: ethers.BytesLike, solver?: URISolver, tries?: number): Promise<ethers.BytesLike>;
|
|
10
10
|
export declare class URISolverIPFS implements URISolver {
|
|
11
11
|
gateway: string;
|
|
12
12
|
constructor(gateway?: string);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/replacer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "EIP-5719 client implementation",
|
|
5
5
|
"repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/replacer",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
"author": "Horizon Blockchain Games",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@0xsequence/abi": "
|
|
13
|
-
"@0xsequence/core": "
|
|
12
|
+
"@0xsequence/abi": "2.0.0",
|
|
13
|
+
"@0xsequence/core": "2.0.0"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"ethers": ">=
|
|
16
|
+
"ethers": ">=6"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {},
|
|
19
19
|
"files": [
|
package/src/cached.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { commons } from '@0xsequence/core'
|
|
|
5
5
|
|
|
6
6
|
export * from './cached'
|
|
7
7
|
|
|
8
|
-
export function eip5719Contract(address: string, provider: ethers.
|
|
8
|
+
export function eip5719Contract(address: string, provider: ethers.Provider): ethers.Contract {
|
|
9
9
|
// TODO: for some reason walletContracts is not being loaded from local
|
|
10
10
|
// remove this code once fixed
|
|
11
11
|
const abi = [
|
|
@@ -31,19 +31,19 @@ export function eip5719Contract(address: string, provider: ethers.providers.Prov
|
|
|
31
31
|
return new ethers.Contract(address, abi, provider)
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
export function eip1271Contract(address: string, provider: ethers.
|
|
34
|
+
export function eip1271Contract(address: string, provider: ethers.Provider): ethers.Contract {
|
|
35
35
|
return new ethers.Contract(address, walletContracts.erc1271.abi, provider)
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export async function isValidSignature(
|
|
39
39
|
address: string,
|
|
40
|
-
provider: ethers.
|
|
40
|
+
provider: ethers.Provider,
|
|
41
41
|
digest: ethers.BytesLike,
|
|
42
42
|
signature: ethers.BytesLike
|
|
43
43
|
): Promise<boolean> {
|
|
44
44
|
// First we try to validate the signature using Ethers
|
|
45
45
|
try {
|
|
46
|
-
const addr = ethers.
|
|
46
|
+
const addr = ethers.recoverAddress(digest, ethers.hexlify(signature))
|
|
47
47
|
if (addr.toLowerCase() === address.toLowerCase()) return true
|
|
48
48
|
} catch {}
|
|
49
49
|
|
|
@@ -72,7 +72,7 @@ async function tryAwait<T>(promise: Promise<T>): Promise<T | undefined> {
|
|
|
72
72
|
|
|
73
73
|
export async function runByEIP5719(
|
|
74
74
|
address: string,
|
|
75
|
-
provider: ethers.
|
|
75
|
+
provider: ethers.Provider,
|
|
76
76
|
digest: ethers.BytesLike,
|
|
77
77
|
signature: ethers.BytesLike,
|
|
78
78
|
solver?: URISolver,
|
|
@@ -94,10 +94,11 @@ export async function runByEIP5719(
|
|
|
94
94
|
const altUri = await tryAwait(eip5719Contract(address, provider).getAlternativeSignature(digest) as Promise<string>)
|
|
95
95
|
if (!altUri || altUri === '') throw new Error('EIP5719 - Invalid signature and no alternative signature')
|
|
96
96
|
|
|
97
|
-
const altSignature = ethers.
|
|
97
|
+
const altSignature = ethers.hexlify(await (solver || new URISolverIPFS()).resolve(altUri))
|
|
98
98
|
if (!altSignature || altSignature === '') throw new Error('EIP5719 - Empty alternative signature')
|
|
99
|
-
if (altSignature === ethers.
|
|
100
|
-
|
|
99
|
+
if (altSignature === ethers.hexlify(signature)) {
|
|
100
|
+
throw new Error('EIP5719 - Alternative signature is invalid or the same')
|
|
101
|
+
}
|
|
101
102
|
return runByEIP5719(address, provider, digest, altSignature, solver, tries + 1)
|
|
102
103
|
}
|
|
103
104
|
|