@1inch/solidity-utils 5.0.0 → 5.1.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/src/bySig.d.ts +50 -0
- package/dist/src/bySig.js +77 -0
- package/dist/src/bySig.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Wallet } from 'ethers';
|
|
2
|
+
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers';
|
|
3
|
+
/**
|
|
4
|
+
* Enum defining types of nonces.
|
|
5
|
+
*/
|
|
6
|
+
export declare enum NonceType {
|
|
7
|
+
Account = 0,// Nonce for account
|
|
8
|
+
Selector = 1,// Nonce for selector
|
|
9
|
+
Unique = 2
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Builds traits for {bySig} contract by combining params.
|
|
13
|
+
* @param nonceType The type of nonce to use. Default is NonceType.Account.
|
|
14
|
+
* @param deadline The deadline for the message. Default is 0.
|
|
15
|
+
* @param relayer The relayer address. Default is the zero address.
|
|
16
|
+
* @param nonce The nonce. Default is 0.
|
|
17
|
+
* @returns A bigint representing the combined traits.
|
|
18
|
+
* @throws Error if provided with invalid parameters.
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildBySigTraits({ nonceType, deadline, relayer, nonce, }?: {
|
|
21
|
+
nonceType?: NonceType | undefined;
|
|
22
|
+
deadline?: number | undefined;
|
|
23
|
+
relayer?: string | undefined;
|
|
24
|
+
nonce?: number | undefined;
|
|
25
|
+
}): bigint;
|
|
26
|
+
export interface SignedCallStruct {
|
|
27
|
+
traits: bigint;
|
|
28
|
+
data: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Computes the EIP-712 hash for a given bySig call.
|
|
32
|
+
* @param name The user readable name of EIP-712 domain.
|
|
33
|
+
* @param version The version of the EIP-712 domain.
|
|
34
|
+
* @param chainId The unique identifier for the blockchain network.
|
|
35
|
+
* @param verifyingContract The Ethereum address of the contract that will verify the signature. This ties the signature to a specific contract.
|
|
36
|
+
* @param sig The data to be signed.
|
|
37
|
+
* @returns The EIP-712 hash of the fully encoded data.
|
|
38
|
+
*/
|
|
39
|
+
export declare function hashBySig(name: string, version: string, chainId: bigint, verifyingContract: string, sig: SignedCallStruct): string;
|
|
40
|
+
/**
|
|
41
|
+
* Signs a given data for {bySig} contract call using EIP-712 standard.
|
|
42
|
+
* @param name The user readable name of EIP-712 domain.
|
|
43
|
+
* @param version The version of the EIP-712 domain.
|
|
44
|
+
* @param chainId The unique identifier for the blockchain network.
|
|
45
|
+
* @param verifyingContract The Ethereum address of the contract that will verify the signature. This ties the signature to a specific contract.
|
|
46
|
+
* @param signer The wallet or signer to sign the data.
|
|
47
|
+
* @param signedCall The call data to be signed, consisting of traits and data.
|
|
48
|
+
* @returns A Promise that resolves to the signature.
|
|
49
|
+
*/
|
|
50
|
+
export declare function signSignedCall(name: string, version: string, chainId: bigint | string, verifyingContract: string, signer: Wallet | SignerWithAddress, signedCall: SignedCallStruct): Promise<string>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.signSignedCall = exports.hashBySig = exports.buildBySigTraits = exports.NonceType = void 0;
|
|
4
|
+
const hardhat_1 = require("hardhat");
|
|
5
|
+
const prelude_1 = require("./prelude");
|
|
6
|
+
/**
|
|
7
|
+
* Enum defining types of nonces.
|
|
8
|
+
*/
|
|
9
|
+
var NonceType;
|
|
10
|
+
(function (NonceType) {
|
|
11
|
+
NonceType[NonceType["Account"] = 0] = "Account";
|
|
12
|
+
NonceType[NonceType["Selector"] = 1] = "Selector";
|
|
13
|
+
NonceType[NonceType["Unique"] = 2] = "Unique";
|
|
14
|
+
})(NonceType || (exports.NonceType = NonceType = {}));
|
|
15
|
+
/**
|
|
16
|
+
* Builds traits for {bySig} contract by combining params.
|
|
17
|
+
* @param nonceType The type of nonce to use. Default is NonceType.Account.
|
|
18
|
+
* @param deadline The deadline for the message. Default is 0.
|
|
19
|
+
* @param relayer The relayer address. Default is the zero address.
|
|
20
|
+
* @param nonce The nonce. Default is 0.
|
|
21
|
+
* @returns A bigint representing the combined traits.
|
|
22
|
+
* @throws Error if provided with invalid parameters.
|
|
23
|
+
*/
|
|
24
|
+
function buildBySigTraits({ nonceType = NonceType.Account, deadline = 0, relayer = prelude_1.constants.ZERO_ADDRESS.toString(), nonce = 0, } = {}) {
|
|
25
|
+
if (nonceType > 3) {
|
|
26
|
+
throw new Error('Wrong nonce type, it should be less than 4');
|
|
27
|
+
}
|
|
28
|
+
if (deadline > 0xffffffffff) {
|
|
29
|
+
throw new Error('Wrong deadline, it should be less than 0xffffffff');
|
|
30
|
+
}
|
|
31
|
+
if (relayer.length > 42) {
|
|
32
|
+
throw new Error('Wrong relayer address, it should be less than 42 symbols');
|
|
33
|
+
}
|
|
34
|
+
if (nonce > 0xffffffffffffffffffffffffffffffffn) {
|
|
35
|
+
throw new Error('Wrong nonce, it should not be more than 128 bits');
|
|
36
|
+
}
|
|
37
|
+
return (BigInt(nonceType) << 254n) +
|
|
38
|
+
(BigInt(deadline) << 208n) +
|
|
39
|
+
((BigInt(relayer) & 0xffffffffffffffffffffn) << 128n) +
|
|
40
|
+
BigInt(nonce);
|
|
41
|
+
}
|
|
42
|
+
exports.buildBySigTraits = buildBySigTraits;
|
|
43
|
+
/**
|
|
44
|
+
* Computes the EIP-712 hash for a given bySig call.
|
|
45
|
+
* @param name The user readable name of EIP-712 domain.
|
|
46
|
+
* @param version The version of the EIP-712 domain.
|
|
47
|
+
* @param chainId The unique identifier for the blockchain network.
|
|
48
|
+
* @param verifyingContract The Ethereum address of the contract that will verify the signature. This ties the signature to a specific contract.
|
|
49
|
+
* @param sig The data to be signed.
|
|
50
|
+
* @returns The EIP-712 hash of the fully encoded data.
|
|
51
|
+
*/
|
|
52
|
+
function hashBySig(name, version, chainId, verifyingContract, sig) {
|
|
53
|
+
const domain = { name, version, chainId, verifyingContract };
|
|
54
|
+
const types = {
|
|
55
|
+
SignedCall: [
|
|
56
|
+
{ name: 'traits', type: 'uint256' },
|
|
57
|
+
{ name: 'data', type: 'bytes' },
|
|
58
|
+
],
|
|
59
|
+
};
|
|
60
|
+
return hardhat_1.ethers.TypedDataEncoder.hash(domain, types, sig);
|
|
61
|
+
}
|
|
62
|
+
exports.hashBySig = hashBySig;
|
|
63
|
+
/**
|
|
64
|
+
* Signs a given data for {bySig} contract call using EIP-712 standard.
|
|
65
|
+
* @param name The user readable name of EIP-712 domain.
|
|
66
|
+
* @param version The version of the EIP-712 domain.
|
|
67
|
+
* @param chainId The unique identifier for the blockchain network.
|
|
68
|
+
* @param verifyingContract The Ethereum address of the contract that will verify the signature. This ties the signature to a specific contract.
|
|
69
|
+
* @param signer The wallet or signer to sign the data.
|
|
70
|
+
* @param signedCall The call data to be signed, consisting of traits and data.
|
|
71
|
+
* @returns A Promise that resolves to the signature.
|
|
72
|
+
*/
|
|
73
|
+
function signSignedCall(name, version, chainId, verifyingContract, signer, signedCall) {
|
|
74
|
+
return signer.signTypedData({ name, version, chainId, verifyingContract }, { SignedCall: [{ name: 'traits', type: 'uint256' }, { name: 'data', type: 'bytes' }] }, signedCall);
|
|
75
|
+
}
|
|
76
|
+
exports.signSignedCall = signSignedCall;
|
|
77
|
+
//# sourceMappingURL=bySig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bySig.js","sourceRoot":"","sources":["../../src/bySig.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,uCAAsC;AAItC;;GAEG;AACH,IAAY,SAIX;AAJD,WAAY,SAAS;IACjB,+CAAO,CAAA;IACP,iDAAQ,CAAA;IACR,6CAAM,CAAA;AACV,CAAC,EAJW,SAAS,yBAAT,SAAS,QAIpB;AAED;;;;;;;;GAQG;AACH,SAAgB,g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,CAAC;IACF,OAAO,gBAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;AAC5D,CAAC;AATD,8BASC;AAED;;;;;;;;;GASG;AACH,SAAgB,cAAc,CAC1B,IAAY,EACZ,OAAe,EACf,OAAwB,EACxB,iBAAyB,EACzB,MAAkC,EAClC,UAA4B;IAE5B,OAAO,MAAM,CAAC,aAAa,CACvB,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,EAC7C,EAAE,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,EACtF,UAAU,CACb,CAAC;AACN,CAAC;AAbD,wCAaC"}
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// created from 'create-ts-index'
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
tslib_1.__exportStar(require("./bySig"), exports);
|
|
5
6
|
tslib_1.__exportStar(require("./expect"), exports);
|
|
6
7
|
tslib_1.__exportStar(require("./permit"), exports);
|
|
7
8
|
tslib_1.__exportStar(require("./prelude"), exports);
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,iCAAiC;;;AAEjC,mDAAyB;AACzB,mDAAyB;AACzB,oDAA0B;AAC1B,uDAA6B;AAC7B,kDAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,iCAAiC;;;AAEjC,kDAAwB;AACxB,mDAAyB;AACzB,mDAAyB;AACzB,oDAA0B;AAC1B,uDAA6B;AAC7B,kDAAwB"}
|