@0xsequence/replacer 2.3.17 → 2.3.18

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.
@@ -1,2 +1,2 @@
1
- export * from "./declarations/src/index.js";
2
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMHhzZXF1ZW5jZS1yZXBsYWNlci5janMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4vZGVjbGFyYXRpb25zL3NyYy9pbmRleC5kLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBIn0=
1
+ export * from "../src/index.js";
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMHhzZXF1ZW5jZS1yZXBsYWNlci5janMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9
@@ -1,7 +1,16 @@
1
- 'use strict';
1
+ "use strict";
2
+ // this file might look strange and you might be wondering what it's for
3
+ // it's lets you import your source files by importing this entrypoint
4
+ // as you would import it if it was built with preconstruct build
5
+ // this file is slightly different to some others though
6
+ // it has a require hook which compiles your code with Babel
7
+ // this means that you don't have to set up @babel/register or anything like that
8
+ // but you can still require this module and it'll be compiled
2
9
 
3
- if (process.env.NODE_ENV === "production") {
4
- module.exports = require("./0xsequence-replacer.cjs.prod.js");
5
- } else {
6
- module.exports = require("./0xsequence-replacer.cjs.dev.js");
7
- }
10
+ // this bit of code imports the require hook and registers it
11
+ let unregister = require("../../../node_modules/.pnpm/@preconstruct+hook@0.4.0/node_modules/@preconstruct/hook").___internalHook(typeof __dirname === 'undefined' ? undefined : __dirname, "../../..", "..");
12
+
13
+ // this re-exports the source file
14
+ module.exports = require("../src/index.ts");
15
+
16
+ unregister();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xsequence/replacer",
3
- "version": "2.3.17",
3
+ "version": "2.3.18",
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",
@@ -12,8 +12,8 @@
12
12
  "ethers": ">=6"
13
13
  },
14
14
  "dependencies": {
15
- "@0xsequence/abi": "2.3.17",
16
- "@0xsequence/core": "2.3.17"
15
+ "@0xsequence/core": "2.3.18",
16
+ "@0xsequence/abi": "2.3.18"
17
17
  },
18
18
  "devDependencies": {},
19
19
  "files": [
@@ -1,127 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var ethers = require('ethers');
6
- var abi = require('@0xsequence/abi');
7
- var core = require('@0xsequence/core');
8
-
9
- function useGateway(uri, gateway) {
10
- const clean = uri.replace('ipfs://ipfs/', '').replace('ipfs://', '');
11
- if (uri.startsWith('ipfs://')) return `${gateway}${clean}`;
12
- return uri;
13
- }
14
- function isIPFS(uri) {
15
- return uri.startsWith('ipfs://');
16
- }
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
-
40
- function eip5719Contract(address, provider) {
41
- // TODO: for some reason walletContracts is not being loaded from local
42
- // remove this code once fixed
43
- const abi = [{
44
- inputs: [{
45
- internalType: 'bytes32',
46
- type: 'bytes32'
47
- }],
48
- name: 'getAlternativeSignature',
49
- outputs: [{
50
- internalType: 'string',
51
- type: 'string'
52
- }],
53
- stateMutability: 'view',
54
- type: 'function'
55
- }];
56
- return new ethers.ethers.Contract(address, abi, provider);
57
- }
58
- function eip1271Contract(address, provider) {
59
- return new ethers.ethers.Contract(address, abi.walletContracts.erc1271.abi, provider);
60
- }
61
- async function isValidSignature(address, provider, digest, signature) {
62
- // First we try to validate the signature using Ethers
63
- try {
64
- const addr = ethers.ethers.recoverAddress(digest, ethers.ethers.hexlify(signature));
65
- if (addr.toLowerCase() === address.toLowerCase()) return true;
66
- } catch (_unused) {}
67
-
68
- // Then we try to validate the signature using EIP1271
69
- try {
70
- const contract = eip1271Contract(address, provider);
71
- const value = await contract.isValidSignature(digest, signature);
72
- if (value === abi.walletContracts.erc1271.returns) return true;
73
- } catch (_unused2) {}
74
-
75
- // If all else fails, we return false
76
- return false;
77
- }
78
- async function tryAwait(promise) {
79
- try {
80
- return await promise;
81
- } catch (_unused3) {
82
- return undefined;
83
- }
84
- }
85
- async function runByEIP5719(address, provider, digest, signature, solver, tries = 0) {
86
- if (tries > 10) throw new Error('EIP5719 - Too many tries');
87
- if (core.commons.signer.canRecover(signature)) {
88
- const recoveredAddr = core.commons.signer.recoverSigner(digest, signature);
89
- if (recoveredAddr && recoveredAddr.toLowerCase() === address.toLowerCase()) return signature;
90
- }
91
- try {
92
- if (await core.commons.signer.isValidSignature(address, digest, signature, provider)) {
93
- return signature;
94
- }
95
- } catch (_unused4) {}
96
- const altUri = await tryAwait(eip5719Contract(address, provider).getAlternativeSignature(digest));
97
- if (!altUri || altUri === '') throw new Error('EIP5719 - Invalid signature and no alternative signature');
98
- const altSignature = ethers.ethers.hexlify(await (solver || new URISolverIPFS()).resolve(altUri));
99
- if (!altSignature || altSignature === '') throw new Error('EIP5719 - Empty alternative signature');
100
- if (altSignature === ethers.ethers.hexlify(signature)) {
101
- throw new Error('EIP5719 - Alternative signature is invalid or the same');
102
- }
103
- return runByEIP5719(address, provider, digest, altSignature, solver, tries + 1);
104
- }
105
- class URISolverIPFS {
106
- constructor(gateway = 'https://cloudflare-ipfs.com/ipfs/') {
107
- var _this = this;
108
- this.gateway = gateway;
109
- this.uri = uri => {
110
- if (isIPFS(uri)) return useGateway(uri, this.gateway);
111
- return uri;
112
- };
113
- this.resolve = async function (uri) {
114
- const url = _this.uri(uri);
115
- const res = await fetch(url);
116
- if (!res.ok) throw new Error(`URISolverIPFS - Failed to fetch ${url}`);
117
- return await res.text();
118
- };
119
- }
120
- }
121
-
122
- exports.CachedEIP5719 = CachedEIP5719;
123
- exports.URISolverIPFS = URISolverIPFS;
124
- exports.eip1271Contract = eip1271Contract;
125
- exports.eip5719Contract = eip5719Contract;
126
- exports.isValidSignature = isValidSignature;
127
- exports.runByEIP5719 = runByEIP5719;
@@ -1,127 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var ethers = require('ethers');
6
- var abi = require('@0xsequence/abi');
7
- var core = require('@0xsequence/core');
8
-
9
- function useGateway(uri, gateway) {
10
- const clean = uri.replace('ipfs://ipfs/', '').replace('ipfs://', '');
11
- if (uri.startsWith('ipfs://')) return `${gateway}${clean}`;
12
- return uri;
13
- }
14
- function isIPFS(uri) {
15
- return uri.startsWith('ipfs://');
16
- }
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
-
40
- function eip5719Contract(address, provider) {
41
- // TODO: for some reason walletContracts is not being loaded from local
42
- // remove this code once fixed
43
- const abi = [{
44
- inputs: [{
45
- internalType: 'bytes32',
46
- type: 'bytes32'
47
- }],
48
- name: 'getAlternativeSignature',
49
- outputs: [{
50
- internalType: 'string',
51
- type: 'string'
52
- }],
53
- stateMutability: 'view',
54
- type: 'function'
55
- }];
56
- return new ethers.ethers.Contract(address, abi, provider);
57
- }
58
- function eip1271Contract(address, provider) {
59
- return new ethers.ethers.Contract(address, abi.walletContracts.erc1271.abi, provider);
60
- }
61
- async function isValidSignature(address, provider, digest, signature) {
62
- // First we try to validate the signature using Ethers
63
- try {
64
- const addr = ethers.ethers.recoverAddress(digest, ethers.ethers.hexlify(signature));
65
- if (addr.toLowerCase() === address.toLowerCase()) return true;
66
- } catch (_unused) {}
67
-
68
- // Then we try to validate the signature using EIP1271
69
- try {
70
- const contract = eip1271Contract(address, provider);
71
- const value = await contract.isValidSignature(digest, signature);
72
- if (value === abi.walletContracts.erc1271.returns) return true;
73
- } catch (_unused2) {}
74
-
75
- // If all else fails, we return false
76
- return false;
77
- }
78
- async function tryAwait(promise) {
79
- try {
80
- return await promise;
81
- } catch (_unused3) {
82
- return undefined;
83
- }
84
- }
85
- async function runByEIP5719(address, provider, digest, signature, solver, tries = 0) {
86
- if (tries > 10) throw new Error('EIP5719 - Too many tries');
87
- if (core.commons.signer.canRecover(signature)) {
88
- const recoveredAddr = core.commons.signer.recoverSigner(digest, signature);
89
- if (recoveredAddr && recoveredAddr.toLowerCase() === address.toLowerCase()) return signature;
90
- }
91
- try {
92
- if (await core.commons.signer.isValidSignature(address, digest, signature, provider)) {
93
- return signature;
94
- }
95
- } catch (_unused4) {}
96
- const altUri = await tryAwait(eip5719Contract(address, provider).getAlternativeSignature(digest));
97
- if (!altUri || altUri === '') throw new Error('EIP5719 - Invalid signature and no alternative signature');
98
- const altSignature = ethers.ethers.hexlify(await (solver || new URISolverIPFS()).resolve(altUri));
99
- if (!altSignature || altSignature === '') throw new Error('EIP5719 - Empty alternative signature');
100
- if (altSignature === ethers.ethers.hexlify(signature)) {
101
- throw new Error('EIP5719 - Alternative signature is invalid or the same');
102
- }
103
- return runByEIP5719(address, provider, digest, altSignature, solver, tries + 1);
104
- }
105
- class URISolverIPFS {
106
- constructor(gateway = 'https://cloudflare-ipfs.com/ipfs/') {
107
- var _this = this;
108
- this.gateway = gateway;
109
- this.uri = uri => {
110
- if (isIPFS(uri)) return useGateway(uri, this.gateway);
111
- return uri;
112
- };
113
- this.resolve = async function (uri) {
114
- const url = _this.uri(uri);
115
- const res = await fetch(url);
116
- if (!res.ok) throw new Error(`URISolverIPFS - Failed to fetch ${url}`);
117
- return await res.text();
118
- };
119
- }
120
- }
121
-
122
- exports.CachedEIP5719 = CachedEIP5719;
123
- exports.URISolverIPFS = URISolverIPFS;
124
- exports.eip1271Contract = eip1271Contract;
125
- exports.eip5719Contract = eip5719Contract;
126
- exports.isValidSignature = isValidSignature;
127
- exports.runByEIP5719 = runByEIP5719;
@@ -1,118 +0,0 @@
1
- import { ethers } from 'ethers';
2
- import { walletContracts } from '@0xsequence/abi';
3
- import { commons } from '@0xsequence/core';
4
-
5
- function useGateway(uri, gateway) {
6
- const clean = uri.replace('ipfs://ipfs/', '').replace('ipfs://', '');
7
- if (uri.startsWith('ipfs://')) return `${gateway}${clean}`;
8
- return uri;
9
- }
10
- function isIPFS(uri) {
11
- return uri.startsWith('ipfs://');
12
- }
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
-
36
- function eip5719Contract(address, provider) {
37
- // TODO: for some reason walletContracts is not being loaded from local
38
- // remove this code once fixed
39
- const abi = [{
40
- inputs: [{
41
- internalType: 'bytes32',
42
- type: 'bytes32'
43
- }],
44
- name: 'getAlternativeSignature',
45
- outputs: [{
46
- internalType: 'string',
47
- type: 'string'
48
- }],
49
- stateMutability: 'view',
50
- type: 'function'
51
- }];
52
- return new ethers.Contract(address, abi, provider);
53
- }
54
- function eip1271Contract(address, provider) {
55
- return new ethers.Contract(address, walletContracts.erc1271.abi, provider);
56
- }
57
- async function isValidSignature(address, provider, digest, signature) {
58
- // First we try to validate the signature using Ethers
59
- try {
60
- const addr = ethers.recoverAddress(digest, ethers.hexlify(signature));
61
- if (addr.toLowerCase() === address.toLowerCase()) return true;
62
- } catch (_unused) {}
63
-
64
- // Then we try to validate the signature using EIP1271
65
- try {
66
- const contract = eip1271Contract(address, provider);
67
- const value = await contract.isValidSignature(digest, signature);
68
- if (value === walletContracts.erc1271.returns) return true;
69
- } catch (_unused2) {}
70
-
71
- // If all else fails, we return false
72
- return false;
73
- }
74
- async function tryAwait(promise) {
75
- try {
76
- return await promise;
77
- } catch (_unused3) {
78
- return undefined;
79
- }
80
- }
81
- async function runByEIP5719(address, provider, digest, signature, solver, tries = 0) {
82
- if (tries > 10) throw new Error('EIP5719 - Too many tries');
83
- if (commons.signer.canRecover(signature)) {
84
- const recoveredAddr = commons.signer.recoverSigner(digest, signature);
85
- if (recoveredAddr && recoveredAddr.toLowerCase() === address.toLowerCase()) return signature;
86
- }
87
- try {
88
- if (await commons.signer.isValidSignature(address, digest, signature, provider)) {
89
- return signature;
90
- }
91
- } catch (_unused4) {}
92
- const altUri = await tryAwait(eip5719Contract(address, provider).getAlternativeSignature(digest));
93
- if (!altUri || altUri === '') throw new Error('EIP5719 - Invalid signature and no alternative signature');
94
- const altSignature = ethers.hexlify(await (solver || new URISolverIPFS()).resolve(altUri));
95
- if (!altSignature || altSignature === '') throw new Error('EIP5719 - Empty alternative signature');
96
- if (altSignature === ethers.hexlify(signature)) {
97
- throw new Error('EIP5719 - Alternative signature is invalid or the same');
98
- }
99
- return runByEIP5719(address, provider, digest, altSignature, solver, tries + 1);
100
- }
101
- class URISolverIPFS {
102
- constructor(gateway = 'https://cloudflare-ipfs.com/ipfs/') {
103
- var _this = this;
104
- this.gateway = gateway;
105
- this.uri = uri => {
106
- if (isIPFS(uri)) return useGateway(uri, this.gateway);
107
- return uri;
108
- };
109
- this.resolve = async function (uri) {
110
- const url = _this.uri(uri);
111
- const res = await fetch(url);
112
- if (!res.ok) throw new Error(`URISolverIPFS - Failed to fetch ${url}`);
113
- return await res.text();
114
- };
115
- }
116
- }
117
-
118
- export { CachedEIP5719, URISolverIPFS, eip1271Contract, eip5719Contract, isValidSignature, runByEIP5719 };
@@ -1,10 +0,0 @@
1
- import { ethers } from 'ethers';
2
- import { URISolver } from "./index.js";
3
- export declare class CachedEIP5719 {
4
- provider: ethers.Provider;
5
- solver?: URISolver | undefined;
6
- window: number;
7
- constructor(provider: ethers.Provider, solver?: URISolver | undefined, window?: number);
8
- private pending;
9
- runByEIP5719(address: string, digest: ethers.BytesLike, signature: ethers.BytesLike): Promise<ethers.BytesLike>;
10
- }
@@ -1,15 +0,0 @@
1
- import { ethers } from 'ethers';
2
- export * from "./cached.js";
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
- export interface URISolver {
7
- resolve: (uri: string) => Promise<string>;
8
- }
9
- export declare function runByEIP5719(address: string, provider: ethers.Provider, digest: ethers.BytesLike, signature: ethers.BytesLike, solver?: URISolver, tries?: number): Promise<ethers.BytesLike>;
10
- export declare class URISolverIPFS implements URISolver {
11
- gateway: string;
12
- constructor(gateway?: string);
13
- uri: (uri: string) => string;
14
- resolve: (uri: string) => Promise<string>;
15
- }