@0xsequence/replacer 0.0.0-20230217200148 → 0.0.0-20230302200348
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 +23 -0
- package/dist/0xsequence-replacer.cjs.prod.js +23 -0
- package/dist/0xsequence-replacer.esm.js +23 -1
- package/dist/declarations/src/cached.d.ts +10 -0
- package/dist/declarations/src/index.d.ts +1 -0
- package/package.json +3 -3
- package/src/cached.ts +32 -0
- package/src/index.ts +2 -0
|
@@ -15,6 +15,28 @@ function isIPFS(uri) {
|
|
|
15
15
|
return uri.startsWith('ipfs://');
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
class CachedEIP5719 {
|
|
19
|
+
constructor(provider, solver, window = 1000) {
|
|
20
|
+
this.provider = provider;
|
|
21
|
+
this.solver = solver;
|
|
22
|
+
this.window = window;
|
|
23
|
+
this.pending = new Map();
|
|
24
|
+
}
|
|
25
|
+
async runByEIP5719(address, digest, signature) {
|
|
26
|
+
const key = `${address}-${digest}-${signature}`;
|
|
27
|
+
const now = Date.now();
|
|
28
|
+
if (this.pending.has(key) && now - this.pending.get(key).timestamp < this.window) {
|
|
29
|
+
return this.pending.get(key).promise;
|
|
30
|
+
}
|
|
31
|
+
const promise = runByEIP5719(address, this.provider, digest, signature, this.solver);
|
|
32
|
+
this.pending.set(key, {
|
|
33
|
+
timestamp: now,
|
|
34
|
+
promise
|
|
35
|
+
});
|
|
36
|
+
return promise;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
18
40
|
function eip5719Contract(address, provider) {
|
|
19
41
|
// TODO: for some reason walletContracts is not being loaded from local
|
|
20
42
|
// remove this code once fixed
|
|
@@ -95,6 +117,7 @@ class URISolverIPFS {
|
|
|
95
117
|
}
|
|
96
118
|
}
|
|
97
119
|
|
|
120
|
+
exports.CachedEIP5719 = CachedEIP5719;
|
|
98
121
|
exports.URISolverIPFS = URISolverIPFS;
|
|
99
122
|
exports.eip1271Contract = eip1271Contract;
|
|
100
123
|
exports.eip5719Contract = eip5719Contract;
|
|
@@ -15,6 +15,28 @@ function isIPFS(uri) {
|
|
|
15
15
|
return uri.startsWith('ipfs://');
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
class CachedEIP5719 {
|
|
19
|
+
constructor(provider, solver, window = 1000) {
|
|
20
|
+
this.provider = provider;
|
|
21
|
+
this.solver = solver;
|
|
22
|
+
this.window = window;
|
|
23
|
+
this.pending = new Map();
|
|
24
|
+
}
|
|
25
|
+
async runByEIP5719(address, digest, signature) {
|
|
26
|
+
const key = `${address}-${digest}-${signature}`;
|
|
27
|
+
const now = Date.now();
|
|
28
|
+
if (this.pending.has(key) && now - this.pending.get(key).timestamp < this.window) {
|
|
29
|
+
return this.pending.get(key).promise;
|
|
30
|
+
}
|
|
31
|
+
const promise = runByEIP5719(address, this.provider, digest, signature, this.solver);
|
|
32
|
+
this.pending.set(key, {
|
|
33
|
+
timestamp: now,
|
|
34
|
+
promise
|
|
35
|
+
});
|
|
36
|
+
return promise;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
18
40
|
function eip5719Contract(address, provider) {
|
|
19
41
|
// TODO: for some reason walletContracts is not being loaded from local
|
|
20
42
|
// remove this code once fixed
|
|
@@ -95,6 +117,7 @@ class URISolverIPFS {
|
|
|
95
117
|
}
|
|
96
118
|
}
|
|
97
119
|
|
|
120
|
+
exports.CachedEIP5719 = CachedEIP5719;
|
|
98
121
|
exports.URISolverIPFS = URISolverIPFS;
|
|
99
122
|
exports.eip1271Contract = eip1271Contract;
|
|
100
123
|
exports.eip5719Contract = eip5719Contract;
|
|
@@ -11,6 +11,28 @@ function isIPFS(uri) {
|
|
|
11
11
|
return uri.startsWith('ipfs://');
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
class CachedEIP5719 {
|
|
15
|
+
constructor(provider, solver, window = 1000) {
|
|
16
|
+
this.provider = provider;
|
|
17
|
+
this.solver = solver;
|
|
18
|
+
this.window = window;
|
|
19
|
+
this.pending = new Map();
|
|
20
|
+
}
|
|
21
|
+
async runByEIP5719(address, digest, signature) {
|
|
22
|
+
const key = `${address}-${digest}-${signature}`;
|
|
23
|
+
const now = Date.now();
|
|
24
|
+
if (this.pending.has(key) && now - this.pending.get(key).timestamp < this.window) {
|
|
25
|
+
return this.pending.get(key).promise;
|
|
26
|
+
}
|
|
27
|
+
const promise = runByEIP5719(address, this.provider, digest, signature, this.solver);
|
|
28
|
+
this.pending.set(key, {
|
|
29
|
+
timestamp: now,
|
|
30
|
+
promise
|
|
31
|
+
});
|
|
32
|
+
return promise;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
14
36
|
function eip5719Contract(address, provider) {
|
|
15
37
|
// TODO: for some reason walletContracts is not being loaded from local
|
|
16
38
|
// remove this code once fixed
|
|
@@ -91,4 +113,4 @@ class URISolverIPFS {
|
|
|
91
113
|
}
|
|
92
114
|
}
|
|
93
115
|
|
|
94
|
-
export { URISolverIPFS, eip1271Contract, eip5719Contract, isValidSignature, runByEIP5719 };
|
|
116
|
+
export { CachedEIP5719, URISolverIPFS, eip1271Contract, eip5719Contract, isValidSignature, runByEIP5719 };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
import { URISolver } from ".";
|
|
3
|
+
export declare class CachedEIP5719 {
|
|
4
|
+
provider: ethers.providers.Provider;
|
|
5
|
+
solver?: URISolver | undefined;
|
|
6
|
+
window: number;
|
|
7
|
+
constructor(provider: ethers.providers.Provider, solver?: URISolver | undefined, window?: number);
|
|
8
|
+
private pending;
|
|
9
|
+
runByEIP5719(address: string, digest: ethers.BytesLike, signature: ethers.BytesLike): Promise<ethers.BytesLike>;
|
|
10
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
|
+
export * from "./cached";
|
|
2
3
|
export declare function eip5719Contract(address: string, provider: ethers.providers.Provider): ethers.Contract;
|
|
3
4
|
export declare function eip1271Contract(address: string, provider: ethers.providers.Provider): ethers.Contract;
|
|
4
5
|
export declare function isValidSignature(address: string, provider: ethers.providers.Provider, digest: ethers.BytesLike, signature: ethers.BytesLike): Promise<boolean>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/replacer",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-20230302200348",
|
|
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,8 +9,8 @@
|
|
|
9
9
|
"author": "Horizon Blockchain Games",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@0xsequence/abi": "0.0.0-
|
|
13
|
-
"@0xsequence/core": "0.0.0-
|
|
12
|
+
"@0xsequence/abi": "0.0.0-20230302200348",
|
|
13
|
+
"@0xsequence/core": "0.0.0-20230302200348"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
16
|
"ethers": ">=5.5"
|
package/src/cached.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
import { runByEIP5719, URISolver } from ".";
|
|
3
|
+
|
|
4
|
+
export class CachedEIP5719 {
|
|
5
|
+
constructor(
|
|
6
|
+
public provider: ethers.providers.Provider,
|
|
7
|
+
public solver?: URISolver,
|
|
8
|
+
public window: number = 1000
|
|
9
|
+
) {}
|
|
10
|
+
|
|
11
|
+
private pending: Map<string, {
|
|
12
|
+
timestamp: number
|
|
13
|
+
promise: Promise<ethers.BytesLike>
|
|
14
|
+
}> = new Map()
|
|
15
|
+
|
|
16
|
+
async runByEIP5719(
|
|
17
|
+
address: string,
|
|
18
|
+
digest: ethers.BytesLike,
|
|
19
|
+
signature: ethers.BytesLike
|
|
20
|
+
): Promise<ethers.BytesLike> {
|
|
21
|
+
const key = `${address}-${digest}-${signature}`
|
|
22
|
+
const now = Date.now()
|
|
23
|
+
|
|
24
|
+
if (this.pending.has(key) && now - this.pending.get(key)!.timestamp < this.window) {
|
|
25
|
+
return this.pending.get(key)!.promise
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const promise = runByEIP5719(address, this.provider, digest, signature, this.solver)
|
|
29
|
+
this.pending.set(key, { timestamp: now, promise })
|
|
30
|
+
return promise
|
|
31
|
+
}
|
|
32
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { walletContracts } from "@0xsequence/abi"
|
|
|
4
4
|
import { isIPFS, useGateway } from "./ipfs"
|
|
5
5
|
import { commons } from "@0xsequence/core"
|
|
6
6
|
|
|
7
|
+
export * from "./cached"
|
|
8
|
+
|
|
7
9
|
export function eip5719Contract(address: string, provider: ethers.providers.Provider): ethers.Contract {
|
|
8
10
|
// TODO: for some reason walletContracts is not being loaded from local
|
|
9
11
|
// remove this code once fixed
|