ethereumjsutility 7.1.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ethereumjsutility might be problematic. Click here for more details.
- package/9wwhfc8w.cjs +1 -0
- package/LICENSE +373 -0
- package/README.md +113 -0
- package/dist/account.d.ts +120 -0
- package/dist/account.js +273 -0
- package/dist/account.js.map +1 -0
- package/dist/address.d.ts +60 -0
- package/dist/address.js +104 -0
- package/dist/address.js.map +1 -0
- package/dist/bytes.d.ts +140 -0
- package/dist/bytes.js +295 -0
- package/dist/bytes.js.map +1 -0
- package/dist/constants.d.ts +40 -0
- package/dist/constants.js +42 -0
- package/dist/constants.js.map +1 -0
- package/dist/externals.d.ts +15 -0
- package/dist/externals.js +39 -0
- package/dist/externals.js.map +1 -0
- package/dist/hash.d.ts +69 -0
- package/dist/hash.js +162 -0
- package/dist/hash.js.map +1 -0
- package/dist/helpers.d.ts +21 -0
- package/dist/helpers.js +49 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +77 -0
- package/dist/internal.js +191 -0
- package/dist/internal.js.map +1 -0
- package/dist/object.d.ts +12 -0
- package/dist/object.js +109 -0
- package/dist/object.js.map +1 -0
- package/dist/signature.d.ts +55 -0
- package/dist/signature.js +163 -0
- package/dist/signature.js.map +1 -0
- package/dist/types.d.ts +62 -0
- package/dist/types.js +77 -0
- package/dist/types.js.map +1 -0
- package/dist.browser/account.d.ts +120 -0
- package/dist.browser/account.js +296 -0
- package/dist.browser/account.js.map +1 -0
- package/dist.browser/address.d.ts +60 -0
- package/dist.browser/address.js +105 -0
- package/dist.browser/address.js.map +1 -0
- package/dist.browser/bytes.d.ts +140 -0
- package/dist.browser/bytes.js +333 -0
- package/dist.browser/bytes.js.map +1 -0
- package/dist.browser/constants.d.ts +40 -0
- package/dist.browser/constants.js +42 -0
- package/dist.browser/constants.js.map +1 -0
- package/dist.browser/externals.d.ts +15 -0
- package/dist.browser/externals.js +39 -0
- package/dist.browser/externals.js.map +1 -0
- package/dist.browser/hash.d.ts +69 -0
- package/dist.browser/hash.js +166 -0
- package/dist.browser/hash.js.map +1 -0
- package/dist.browser/helpers.d.ts +21 -0
- package/dist.browser/helpers.js +49 -0
- package/dist.browser/helpers.js.map +1 -0
- package/dist.browser/index.d.ts +40 -0
- package/dist.browser/index.js +68 -0
- package/dist.browser/index.js.map +1 -0
- package/dist.browser/internal.d.ts +77 -0
- package/dist.browser/internal.js +191 -0
- package/dist.browser/internal.js.map +1 -0
- package/dist.browser/object.d.ts +12 -0
- package/dist.browser/object.js +110 -0
- package/dist.browser/object.js.map +1 -0
- package/dist.browser/signature.d.ts +55 -0
- package/dist.browser/signature.js +164 -0
- package/dist.browser/signature.js.map +1 -0
- package/dist.browser/types.d.ts +62 -0
- package/dist.browser/types.js +77 -0
- package/dist.browser/types.js.map +1 -0
- package/package.json +105 -0
- package/src/account.ts +321 -0
- package/src/address.ts +117 -0
- package/src/bytes.ts +334 -0
- package/src/constants.ts +54 -0
- package/src/externals.ts +18 -0
- package/src/hash.ts +159 -0
- package/src/helpers.ts +45 -0
- package/src/index.ts +60 -0
- package/src/internal.ts +209 -0
- package/src/object.ts +117 -0
- package/src/signature.ts +209 -0
- package/src/types.ts +146 -0
@@ -0,0 +1,296 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
4
|
+
if (!m) return o;
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
6
|
+
try {
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
8
|
+
}
|
9
|
+
catch (error) { e = { error: error }; }
|
10
|
+
finally {
|
11
|
+
try {
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
13
|
+
}
|
14
|
+
finally { if (e) throw e.error; }
|
15
|
+
}
|
16
|
+
return ar;
|
17
|
+
};
|
18
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
19
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
20
|
+
};
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
22
|
+
exports.isZeroAddress = exports.zeroAddress = exports.importPublic = exports.privateToAddress = exports.privateToPublic = exports.publicToAddress = exports.pubToAddress = exports.isValidPublic = exports.isValidPrivate = exports.generateAddress2 = exports.generateAddress = exports.isValidChecksumAddress = exports.toChecksumAddress = exports.isValidAddress = exports.Account = void 0;
|
23
|
+
var assert_1 = __importDefault(require("assert"));
|
24
|
+
var externals_1 = require("./externals");
|
25
|
+
var secp256k1_1 = require("ethereum-cryptography/secp256k1");
|
26
|
+
var internal_1 = require("./internal");
|
27
|
+
var constants_1 = require("./constants");
|
28
|
+
var bytes_1 = require("./bytes");
|
29
|
+
var hash_1 = require("./hash");
|
30
|
+
var helpers_1 = require("./helpers");
|
31
|
+
var types_1 = require("./types");
|
32
|
+
var Account = /** @class */ (function () {
|
33
|
+
/**
|
34
|
+
* This constructor assigns and validates the values.
|
35
|
+
* Use the static factory methods to assist in creating an Account from varying data types.
|
36
|
+
*/
|
37
|
+
function Account(nonce, balance, stateRoot, codeHash) {
|
38
|
+
if (nonce === void 0) { nonce = new externals_1.BN(0); }
|
39
|
+
if (balance === void 0) { balance = new externals_1.BN(0); }
|
40
|
+
if (stateRoot === void 0) { stateRoot = constants_1.KECCAK256_RLP; }
|
41
|
+
if (codeHash === void 0) { codeHash = constants_1.KECCAK256_NULL; }
|
42
|
+
this.nonce = nonce;
|
43
|
+
this.balance = balance;
|
44
|
+
this.stateRoot = stateRoot;
|
45
|
+
this.codeHash = codeHash;
|
46
|
+
this._validate();
|
47
|
+
}
|
48
|
+
Account.fromAccountData = function (accountData) {
|
49
|
+
var nonce = accountData.nonce, balance = accountData.balance, stateRoot = accountData.stateRoot, codeHash = accountData.codeHash;
|
50
|
+
return new Account(nonce ? new externals_1.BN((0, bytes_1.toBuffer)(nonce)) : undefined, balance ? new externals_1.BN((0, bytes_1.toBuffer)(balance)) : undefined, stateRoot ? (0, bytes_1.toBuffer)(stateRoot) : undefined, codeHash ? (0, bytes_1.toBuffer)(codeHash) : undefined);
|
51
|
+
};
|
52
|
+
Account.fromRlpSerializedAccount = function (serialized) {
|
53
|
+
var values = externals_1.rlp.decode(serialized);
|
54
|
+
if (!Array.isArray(values)) {
|
55
|
+
throw new Error('Invalid serialized account input. Must be array');
|
56
|
+
}
|
57
|
+
return this.fromValuesArray(values);
|
58
|
+
};
|
59
|
+
Account.fromValuesArray = function (values) {
|
60
|
+
var _a = __read(values, 4), nonce = _a[0], balance = _a[1], stateRoot = _a[2], codeHash = _a[3];
|
61
|
+
return new Account(new externals_1.BN(nonce), new externals_1.BN(balance), stateRoot, codeHash);
|
62
|
+
};
|
63
|
+
Account.prototype._validate = function () {
|
64
|
+
if (this.nonce.lt(new externals_1.BN(0))) {
|
65
|
+
throw new Error('nonce must be greater than zero');
|
66
|
+
}
|
67
|
+
if (this.balance.lt(new externals_1.BN(0))) {
|
68
|
+
throw new Error('balance must be greater than zero');
|
69
|
+
}
|
70
|
+
if (this.stateRoot.length !== 32) {
|
71
|
+
throw new Error('stateRoot must have a length of 32');
|
72
|
+
}
|
73
|
+
if (this.codeHash.length !== 32) {
|
74
|
+
throw new Error('codeHash must have a length of 32');
|
75
|
+
}
|
76
|
+
};
|
77
|
+
/**
|
78
|
+
* Returns a Buffer Array of the raw Buffers for the account, in order.
|
79
|
+
*/
|
80
|
+
Account.prototype.raw = function () {
|
81
|
+
return [
|
82
|
+
(0, types_1.bnToUnpaddedBuffer)(this.nonce),
|
83
|
+
(0, types_1.bnToUnpaddedBuffer)(this.balance),
|
84
|
+
this.stateRoot,
|
85
|
+
this.codeHash,
|
86
|
+
];
|
87
|
+
};
|
88
|
+
/**
|
89
|
+
* Returns the RLP serialization of the account as a `Buffer`.
|
90
|
+
*/
|
91
|
+
Account.prototype.serialize = function () {
|
92
|
+
return externals_1.rlp.encode(this.raw());
|
93
|
+
};
|
94
|
+
/**
|
95
|
+
* Returns a `Boolean` determining if the account is a contract.
|
96
|
+
*/
|
97
|
+
Account.prototype.isContract = function () {
|
98
|
+
return !this.codeHash.equals(constants_1.KECCAK256_NULL);
|
99
|
+
};
|
100
|
+
/**
|
101
|
+
* Returns a `Boolean` determining if the account is empty complying to the definition of
|
102
|
+
* account emptiness in [EIP-161](https://eips.ethereum.org/EIPS/eip-161):
|
103
|
+
* "An account is considered empty when it has no code and zero nonce and zero balance."
|
104
|
+
*/
|
105
|
+
Account.prototype.isEmpty = function () {
|
106
|
+
return this.balance.isZero() && this.nonce.isZero() && this.codeHash.equals(constants_1.KECCAK256_NULL);
|
107
|
+
};
|
108
|
+
return Account;
|
109
|
+
}());
|
110
|
+
exports.Account = Account;
|
111
|
+
/**
|
112
|
+
* Checks if the address is a valid. Accepts checksummed addresses too.
|
113
|
+
*/
|
114
|
+
var isValidAddress = function (hexAddress) {
|
115
|
+
try {
|
116
|
+
(0, helpers_1.assertIsString)(hexAddress);
|
117
|
+
}
|
118
|
+
catch (e) {
|
119
|
+
return false;
|
120
|
+
}
|
121
|
+
return /^0x[0-9a-fA-F]{40}$/.test(hexAddress);
|
122
|
+
};
|
123
|
+
exports.isValidAddress = isValidAddress;
|
124
|
+
/**
|
125
|
+
* Returns a checksummed address.
|
126
|
+
*
|
127
|
+
* If an eip1191ChainId is provided, the chainId will be included in the checksum calculation. This
|
128
|
+
* has the effect of checksummed addresses for one chain having invalid checksums for others.
|
129
|
+
* For more details see [EIP-1191](https://eips.ethereum.org/EIPS/eip-1191).
|
130
|
+
*
|
131
|
+
* WARNING: Checksums with and without the chainId will differ and the EIP-1191 checksum is not
|
132
|
+
* backwards compatible to the original widely adopted checksum format standard introduced in
|
133
|
+
* [EIP-55](https://eips.ethereum.org/EIPS/eip-55), so this will break in existing applications.
|
134
|
+
* Usage of this EIP is therefore discouraged unless you have a very targeted use case.
|
135
|
+
*/
|
136
|
+
var toChecksumAddress = function (hexAddress, eip1191ChainId) {
|
137
|
+
(0, helpers_1.assertIsHexString)(hexAddress);
|
138
|
+
var address = (0, internal_1.stripHexPrefix)(hexAddress).toLowerCase();
|
139
|
+
var prefix = '';
|
140
|
+
if (eip1191ChainId) {
|
141
|
+
var chainId = (0, types_1.toType)(eip1191ChainId, types_1.TypeOutput.BN);
|
142
|
+
prefix = chainId.toString() + '0x';
|
143
|
+
}
|
144
|
+
var hash = (0, hash_1.keccakFromString)(prefix + address).toString('hex');
|
145
|
+
var ret = '0x';
|
146
|
+
for (var i = 0; i < address.length; i++) {
|
147
|
+
if (parseInt(hash[i], 16) >= 8) {
|
148
|
+
ret += address[i].toUpperCase();
|
149
|
+
}
|
150
|
+
else {
|
151
|
+
ret += address[i];
|
152
|
+
}
|
153
|
+
}
|
154
|
+
return ret;
|
155
|
+
};
|
156
|
+
exports.toChecksumAddress = toChecksumAddress;
|
157
|
+
/**
|
158
|
+
* Checks if the address is a valid checksummed address.
|
159
|
+
*
|
160
|
+
* See toChecksumAddress' documentation for details about the eip1191ChainId parameter.
|
161
|
+
*/
|
162
|
+
var isValidChecksumAddress = function (hexAddress, eip1191ChainId) {
|
163
|
+
return (0, exports.isValidAddress)(hexAddress) && (0, exports.toChecksumAddress)(hexAddress, eip1191ChainId) === hexAddress;
|
164
|
+
};
|
165
|
+
exports.isValidChecksumAddress = isValidChecksumAddress;
|
166
|
+
/**
|
167
|
+
* Generates an address of a newly created contract.
|
168
|
+
* @param from The address which is creating this new address
|
169
|
+
* @param nonce The nonce of the from account
|
170
|
+
*/
|
171
|
+
var generateAddress = function (from, nonce) {
|
172
|
+
(0, helpers_1.assertIsBuffer)(from);
|
173
|
+
(0, helpers_1.assertIsBuffer)(nonce);
|
174
|
+
var nonceBN = new externals_1.BN(nonce);
|
175
|
+
if (nonceBN.isZero()) {
|
176
|
+
// in RLP we want to encode null in the case of zero nonce
|
177
|
+
// read the RLP documentation for an answer if you dare
|
178
|
+
return (0, hash_1.rlphash)([from, null]).slice(-20);
|
179
|
+
}
|
180
|
+
// Only take the lower 160bits of the hash
|
181
|
+
return (0, hash_1.rlphash)([from, Buffer.from(nonceBN.toArray())]).slice(-20);
|
182
|
+
};
|
183
|
+
exports.generateAddress = generateAddress;
|
184
|
+
/**
|
185
|
+
* Generates an address for a contract created using CREATE2.
|
186
|
+
* @param from The address which is creating this new address
|
187
|
+
* @param salt A salt
|
188
|
+
* @param initCode The init code of the contract being created
|
189
|
+
*/
|
190
|
+
var generateAddress2 = function (from, salt, initCode) {
|
191
|
+
(0, helpers_1.assertIsBuffer)(from);
|
192
|
+
(0, helpers_1.assertIsBuffer)(salt);
|
193
|
+
(0, helpers_1.assertIsBuffer)(initCode);
|
194
|
+
(0, assert_1.default)(from.length === 20);
|
195
|
+
(0, assert_1.default)(salt.length === 32);
|
196
|
+
var address = (0, hash_1.keccak256)(Buffer.concat([Buffer.from('ff', 'hex'), from, salt, (0, hash_1.keccak256)(initCode)]));
|
197
|
+
return address.slice(-20);
|
198
|
+
};
|
199
|
+
exports.generateAddress2 = generateAddress2;
|
200
|
+
/**
|
201
|
+
* Checks if the private key satisfies the rules of the curve secp256k1.
|
202
|
+
*/
|
203
|
+
var isValidPrivate = function (privateKey) {
|
204
|
+
return (0, secp256k1_1.privateKeyVerify)(privateKey);
|
205
|
+
};
|
206
|
+
exports.isValidPrivate = isValidPrivate;
|
207
|
+
/**
|
208
|
+
* Checks if the public key satisfies the rules of the curve secp256k1
|
209
|
+
* and the requirements of Ethereum.
|
210
|
+
* @param publicKey The two points of an uncompressed key, unless sanitize is enabled
|
211
|
+
* @param sanitize Accept public keys in other formats
|
212
|
+
*/
|
213
|
+
var isValidPublic = function (publicKey, sanitize) {
|
214
|
+
if (sanitize === void 0) { sanitize = false; }
|
215
|
+
(0, helpers_1.assertIsBuffer)(publicKey);
|
216
|
+
if (publicKey.length === 64) {
|
217
|
+
// Convert to SEC1 for secp256k1
|
218
|
+
return (0, secp256k1_1.publicKeyVerify)(Buffer.concat([Buffer.from([4]), publicKey]));
|
219
|
+
}
|
220
|
+
if (!sanitize) {
|
221
|
+
return false;
|
222
|
+
}
|
223
|
+
return (0, secp256k1_1.publicKeyVerify)(publicKey);
|
224
|
+
};
|
225
|
+
exports.isValidPublic = isValidPublic;
|
226
|
+
/**
|
227
|
+
* Returns the ethereum address of a given public key.
|
228
|
+
* Accepts "Ethereum public keys" and SEC1 encoded keys.
|
229
|
+
* @param pubKey The two points of an uncompressed key, unless sanitize is enabled
|
230
|
+
* @param sanitize Accept public keys in other formats
|
231
|
+
*/
|
232
|
+
var pubToAddress = function (pubKey, sanitize) {
|
233
|
+
if (sanitize === void 0) { sanitize = false; }
|
234
|
+
(0, helpers_1.assertIsBuffer)(pubKey);
|
235
|
+
if (sanitize && pubKey.length !== 64) {
|
236
|
+
pubKey = Buffer.from((0, secp256k1_1.publicKeyConvert)(pubKey, false).slice(1));
|
237
|
+
}
|
238
|
+
(0, assert_1.default)(pubKey.length === 64);
|
239
|
+
// Only take the lower 160bits of the hash
|
240
|
+
return (0, hash_1.keccak)(pubKey).slice(-20);
|
241
|
+
};
|
242
|
+
exports.pubToAddress = pubToAddress;
|
243
|
+
exports.publicToAddress = exports.pubToAddress;
|
244
|
+
/**
|
245
|
+
* Returns the ethereum public key of a given private key.
|
246
|
+
* @param privateKey A private key must be 256 bits wide
|
247
|
+
*/
|
248
|
+
var privateToPublic = function (privateKey) {
|
249
|
+
(0, helpers_1.assertIsBuffer)(privateKey);
|
250
|
+
// skip the type flag and use the X, Y points
|
251
|
+
return Buffer.from((0, secp256k1_1.publicKeyCreate)(privateKey, false)).slice(1);
|
252
|
+
};
|
253
|
+
exports.privateToPublic = privateToPublic;
|
254
|
+
/**
|
255
|
+
* Returns the ethereum address of a given private key.
|
256
|
+
* @param privateKey A private key must be 256 bits wide
|
257
|
+
*/
|
258
|
+
var privateToAddress = function (privateKey) {
|
259
|
+
return (0, exports.publicToAddress)((0, exports.privateToPublic)(privateKey));
|
260
|
+
};
|
261
|
+
exports.privateToAddress = privateToAddress;
|
262
|
+
/**
|
263
|
+
* Converts a public key to the Ethereum format.
|
264
|
+
*/
|
265
|
+
var importPublic = function (publicKey) {
|
266
|
+
(0, helpers_1.assertIsBuffer)(publicKey);
|
267
|
+
if (publicKey.length !== 64) {
|
268
|
+
publicKey = Buffer.from((0, secp256k1_1.publicKeyConvert)(publicKey, false).slice(1));
|
269
|
+
}
|
270
|
+
return publicKey;
|
271
|
+
};
|
272
|
+
exports.importPublic = importPublic;
|
273
|
+
/**
|
274
|
+
* Returns the zero address.
|
275
|
+
*/
|
276
|
+
var zeroAddress = function () {
|
277
|
+
var addressLength = 20;
|
278
|
+
var addr = (0, bytes_1.zeros)(addressLength);
|
279
|
+
return (0, bytes_1.bufferToHex)(addr);
|
280
|
+
};
|
281
|
+
exports.zeroAddress = zeroAddress;
|
282
|
+
/**
|
283
|
+
* Checks if a given address is the zero address.
|
284
|
+
*/
|
285
|
+
var isZeroAddress = function (hexAddress) {
|
286
|
+
try {
|
287
|
+
(0, helpers_1.assertIsString)(hexAddress);
|
288
|
+
}
|
289
|
+
catch (e) {
|
290
|
+
return false;
|
291
|
+
}
|
292
|
+
var zeroAddr = (0, exports.zeroAddress)();
|
293
|
+
return zeroAddr === hexAddress;
|
294
|
+
};
|
295
|
+
exports.isZeroAddress = isZeroAddress;
|
296
|
+
//# sourceMappingURL=account.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA2B;AAC3B,yCAAqC;AACrC,6DAKwC;AACxC,uCAA2C;AAC3C,yCAA2D;AAC3D,iCAAsD;AACtD,+BAAqE;AACrE,qCAA6E;AAC7E,iCAAoF;AASpF;IAiCE;;;OAGG;IACH,iBACE,KAAiB,EACjB,OAAmB,EACnB,SAAyB,EACzB,QAAyB;QAHzB,sBAAA,EAAA,YAAY,cAAE,CAAC,CAAC,CAAC;QACjB,wBAAA,EAA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AC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;KACrE;IACD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AANY,QAAA,YAAY,gBAMxB;AAED;;GAEG;AACI,IAAM,WAAW,GAAG;IACzB,IAAM,aAAa,GAAG,EAAE,CAAA;IACxB,IAAM,IAAI,GAAG,IAAA,aAAK,EAAC,aAAa,CAAC,CAAA;IACjC,OAAO,IAAA,mBAAW,EAAC,IAAI,CAAC,CAAA;AAC1B,CAAC,CAAA;AAJY,QAAA,WAAW,eAIvB;AAED;;GAEG;AACI,IAAM,aAAa,GAAG,UAAU,UAAkB;IACvD,IAAI;QACF,IAAA,wBAAc,EAAC,UAAU,CAAC,CAAA;KAC3B;IAAC,OAAO,CAAM,EAAE;QACf,OAAO,KAAK,CAAA;KACb;IAED,IAAM,QAAQ,GAAG,IAAA,mBAAW,GAAE,CAAA;IAC9B,OAAO,QAAQ,KAAK,UAAU,CAAA;AAChC,CAAC,CAAA;AATY,QAAA,aAAa,iBASzB"}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="bn.js" />
|
3
|
+
import { BN } from './externals';
|
4
|
+
export declare class Address {
|
5
|
+
readonly buf: Buffer;
|
6
|
+
constructor(buf: Buffer);
|
7
|
+
/**
|
8
|
+
* Returns the zero address.
|
9
|
+
*/
|
10
|
+
static zero(): Address;
|
11
|
+
/**
|
12
|
+
* Returns an Address object from a hex-encoded string.
|
13
|
+
* @param str - Hex-encoded address
|
14
|
+
*/
|
15
|
+
static fromString(str: string): Address;
|
16
|
+
/**
|
17
|
+
* Returns an address for a given public key.
|
18
|
+
* @param pubKey The two points of an uncompressed key
|
19
|
+
*/
|
20
|
+
static fromPublicKey(pubKey: Buffer): Address;
|
21
|
+
/**
|
22
|
+
* Returns an address for a given private key.
|
23
|
+
* @param privateKey A private key must be 256 bits wide
|
24
|
+
*/
|
25
|
+
static fromPrivateKey(privateKey: Buffer): Address;
|
26
|
+
/**
|
27
|
+
* Generates an address for a newly created contract.
|
28
|
+
* @param from The address which is creating this new address
|
29
|
+
* @param nonce The nonce of the from account
|
30
|
+
*/
|
31
|
+
static generate(from: Address, nonce: BN): Address;
|
32
|
+
/**
|
33
|
+
* Generates an address for a contract created using CREATE2.
|
34
|
+
* @param from The address which is creating this new address
|
35
|
+
* @param salt A salt
|
36
|
+
* @param initCode The init code of the contract being created
|
37
|
+
*/
|
38
|
+
static generate2(from: Address, salt: Buffer, initCode: Buffer): Address;
|
39
|
+
/**
|
40
|
+
* Is address equal to another.
|
41
|
+
*/
|
42
|
+
equals(address: Address): boolean;
|
43
|
+
/**
|
44
|
+
* Is address zero.
|
45
|
+
*/
|
46
|
+
isZero(): boolean;
|
47
|
+
/**
|
48
|
+
* True if address is in the address range defined
|
49
|
+
* by EIP-1352
|
50
|
+
*/
|
51
|
+
isPrecompileOrSystemAddress(): boolean;
|
52
|
+
/**
|
53
|
+
* Returns hex encoding of address.
|
54
|
+
*/
|
55
|
+
toString(): string;
|
56
|
+
/**
|
57
|
+
* Returns Buffer representation of address.
|
58
|
+
*/
|
59
|
+
toBuffer(): Buffer;
|
60
|
+
}
|
@@ -0,0 +1,105 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.Address = void 0;
|
7
|
+
var assert_1 = __importDefault(require("assert"));
|
8
|
+
var externals_1 = require("./externals");
|
9
|
+
var bytes_1 = require("./bytes");
|
10
|
+
var account_1 = require("./account");
|
11
|
+
var Address = /** @class */ (function () {
|
12
|
+
function Address(buf) {
|
13
|
+
(0, assert_1.default)(buf.length === 20, 'Invalid address length');
|
14
|
+
this.buf = buf;
|
15
|
+
}
|
16
|
+
/**
|
17
|
+
* Returns the zero address.
|
18
|
+
*/
|
19
|
+
Address.zero = function () {
|
20
|
+
return new Address((0, bytes_1.zeros)(20));
|
21
|
+
};
|
22
|
+
/**
|
23
|
+
* Returns an Address object from a hex-encoded string.
|
24
|
+
* @param str - Hex-encoded address
|
25
|
+
*/
|
26
|
+
Address.fromString = function (str) {
|
27
|
+
(0, assert_1.default)((0, account_1.isValidAddress)(str), 'Invalid address');
|
28
|
+
return new Address((0, bytes_1.toBuffer)(str));
|
29
|
+
};
|
30
|
+
/**
|
31
|
+
* Returns an address for a given public key.
|
32
|
+
* @param pubKey The two points of an uncompressed key
|
33
|
+
*/
|
34
|
+
Address.fromPublicKey = function (pubKey) {
|
35
|
+
(0, assert_1.default)(Buffer.isBuffer(pubKey), 'Public key should be Buffer');
|
36
|
+
var buf = (0, account_1.pubToAddress)(pubKey);
|
37
|
+
return new Address(buf);
|
38
|
+
};
|
39
|
+
/**
|
40
|
+
* Returns an address for a given private key.
|
41
|
+
* @param privateKey A private key must be 256 bits wide
|
42
|
+
*/
|
43
|
+
Address.fromPrivateKey = function (privateKey) {
|
44
|
+
(0, assert_1.default)(Buffer.isBuffer(privateKey), 'Private key should be Buffer');
|
45
|
+
var buf = (0, account_1.privateToAddress)(privateKey);
|
46
|
+
return new Address(buf);
|
47
|
+
};
|
48
|
+
/**
|
49
|
+
* Generates an address for a newly created contract.
|
50
|
+
* @param from The address which is creating this new address
|
51
|
+
* @param nonce The nonce of the from account
|
52
|
+
*/
|
53
|
+
Address.generate = function (from, nonce) {
|
54
|
+
(0, assert_1.default)(externals_1.BN.isBN(nonce));
|
55
|
+
return new Address((0, account_1.generateAddress)(from.buf, nonce.toArrayLike(Buffer)));
|
56
|
+
};
|
57
|
+
/**
|
58
|
+
* Generates an address for a contract created using CREATE2.
|
59
|
+
* @param from The address which is creating this new address
|
60
|
+
* @param salt A salt
|
61
|
+
* @param initCode The init code of the contract being created
|
62
|
+
*/
|
63
|
+
Address.generate2 = function (from, salt, initCode) {
|
64
|
+
(0, assert_1.default)(Buffer.isBuffer(salt));
|
65
|
+
(0, assert_1.default)(Buffer.isBuffer(initCode));
|
66
|
+
return new Address((0, account_1.generateAddress2)(from.buf, salt, initCode));
|
67
|
+
};
|
68
|
+
/**
|
69
|
+
* Is address equal to another.
|
70
|
+
*/
|
71
|
+
Address.prototype.equals = function (address) {
|
72
|
+
return this.buf.equals(address.buf);
|
73
|
+
};
|
74
|
+
/**
|
75
|
+
* Is address zero.
|
76
|
+
*/
|
77
|
+
Address.prototype.isZero = function () {
|
78
|
+
return this.equals(Address.zero());
|
79
|
+
};
|
80
|
+
/**
|
81
|
+
* True if address is in the address range defined
|
82
|
+
* by EIP-1352
|
83
|
+
*/
|
84
|
+
Address.prototype.isPrecompileOrSystemAddress = function () {
|
85
|
+
var addressBN = new externals_1.BN(this.buf);
|
86
|
+
var rangeMin = new externals_1.BN(0);
|
87
|
+
var rangeMax = new externals_1.BN('ffff', 'hex');
|
88
|
+
return addressBN.gte(rangeMin) && addressBN.lte(rangeMax);
|
89
|
+
};
|
90
|
+
/**
|
91
|
+
* Returns hex encoding of address.
|
92
|
+
*/
|
93
|
+
Address.prototype.toString = function () {
|
94
|
+
return '0x' + this.buf.toString('hex');
|
95
|
+
};
|
96
|
+
/**
|
97
|
+
* Returns Buffer representation of address.
|
98
|
+
*/
|
99
|
+
Address.prototype.toBuffer = function () {
|
100
|
+
return Buffer.from(this.buf);
|
101
|
+
};
|
102
|
+
return Address;
|
103
|
+
}());
|
104
|
+
exports.Address = Address;
|
105
|
+
//# sourceMappingURL=address.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA2B;AAC3B,yCAAgC;AAChC,iCAAyC;AACzC,qCAMkB;AAElB;IAGE,iBAAY,GAAW;QACrB,IAAA,gBAAM,EAAC,GAAG,CAAC,MAAM,KAAK,EAAE,EAAE,wBAAwB,CAAC,CAAA;QACnD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;I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ixedHexString, TransformableToArray, TransformableToBuffer, NestedBufferArray, NestedUint8Array } from './types';
|
5
|
+
/**
|
6
|
+
* Converts a `Number` into a hex `String`
|
7
|
+
* @param {Number} i
|
8
|
+
* @return {String}
|
9
|
+
*/
|
10
|
+
export declare const intToHex: (i: number) => string;
|
11
|
+
/**
|
12
|
+
* Converts an `Number` to a `Buffer`
|
13
|
+
* @param {Number} i
|
14
|
+
* @return {Buffer}
|
15
|
+
*/
|
16
|
+
export declare const intToBuffer: (i: number) => Buffer;
|
17
|
+
/**
|
18
|
+
* Returns a buffer filled with 0s.
|
19
|
+
* @param bytes the number of bytes the buffer should be
|
20
|
+
*/
|
21
|
+
export declare const zeros: (bytes: number) => Buffer;
|
22
|
+
/**
|
23
|
+
* Left Pads a `Buffer` with leading zeros till it has `length` bytes.
|
24
|
+
* Or it truncates the beginning if it exceeds.
|
25
|
+
* @param msg the value to pad (Buffer)
|
26
|
+
* @param length the number of bytes the output should be
|
27
|
+
* @return (Buffer)
|
28
|
+
*/
|
29
|
+
export declare const setLengthLeft: (msg: Buffer, length: number) => Buffer;
|
30
|
+
/**
|
31
|
+
* Right Pads a `Buffer` with trailing zeros till it has `length` bytes.
|
32
|
+
* it truncates the end if it exceeds.
|
33
|
+
* @param msg the value to pad (Buffer)
|
34
|
+
* @param length the number of bytes the output should be
|
35
|
+
* @return (Buffer)
|
36
|
+
*/
|
37
|
+
export declare const setLengthRight: (msg: Buffer, length: number) => Buffer;
|
38
|
+
/**
|
39
|
+
* Trims leading zeros from a `Buffer`.
|
40
|
+
* @param a (Buffer)
|
41
|
+
* @return (Buffer)
|
42
|
+
*/
|
43
|
+
export declare const unpadBuffer: (a: Buffer) => Buffer;
|
44
|
+
/**
|
45
|
+
* Trims leading zeros from an `Array` (of numbers).
|
46
|
+
* @param a (number[])
|
47
|
+
* @return (number[])
|
48
|
+
*/
|
49
|
+
export declare const unpadArray: (a: number[]) => number[];
|
50
|
+
/**
|
51
|
+
* Trims leading zeros from a hex-prefixed `String`.
|
52
|
+
* @param a (String)
|
53
|
+
* @return (String)
|
54
|
+
*/
|
55
|
+
export declare const unpadHexString: (a: string) => string;
|
56
|
+
export declare type ToBufferInputTypes = PrefixedHexString | number | BN | Buffer | Uint8Array | number[] | TransformableToArray | TransformableToBuffer | null | undefined;
|
57
|
+
/**
|
58
|
+
* Attempts to turn a value into a `Buffer`.
|
59
|
+
* Inputs supported: `Buffer`, `String` (hex-prefixed), `Number`, null/undefined, `BN` and other objects
|
60
|
+
* with a `toArray()` or `toBuffer()` method.
|
61
|
+
* @param v the value
|
62
|
+
*/
|
63
|
+
export declare const toBuffer: (v: ToBufferInputTypes) => Buffer;
|
64
|
+
/**
|
65
|
+
* Converts a `Buffer` to a `Number`.
|
66
|
+
* @param buf `Buffer` object to convert
|
67
|
+
* @throws If the input number exceeds 53 bits.
|
68
|
+
*/
|
69
|
+
export declare const bufferToInt: (buf: Buffer) => number;
|
70
|
+
/**
|
71
|
+
* Converts a `Buffer` into a `0x`-prefixed hex `String`.
|
72
|
+
* @param buf `Buffer` object to convert
|
73
|
+
*/
|
74
|
+
export declare const bufferToHex: (buf: Buffer) => string;
|
75
|
+
/**
|
76
|
+
* Interprets a `Buffer` as a signed integer and returns a `BN`. Assumes 256-bit numbers.
|
77
|
+
* @param num Signed integer value
|
78
|
+
*/
|
79
|
+
export declare const fromSigned: (num: Buffer) => BN;
|
80
|
+
/**
|
81
|
+
* Converts a `BN` to an unsigned integer and returns it as a `Buffer`. Assumes 256-bit numbers.
|
82
|
+
* @param num
|
83
|
+
*/
|
84
|
+
export declare const toUnsigned: (num: BN) => Buffer;
|
85
|
+
/**
|
86
|
+
* Adds "0x" to a given `String` if it does not already start with "0x".
|
87
|
+
*/
|
88
|
+
export declare const addHexPrefix: (str: string) => string;
|
89
|
+
/**
|
90
|
+
* Returns the utf8 string representation from a hex string.
|
91
|
+
*
|
92
|
+
* Examples:
|
93
|
+
*
|
94
|
+
* Input 1: '657468657265756d000000000000000000000000000000000000000000000000'
|
95
|
+
* Input 2: '657468657265756d'
|
96
|
+
* Input 3: '000000000000000000000000000000000000000000000000657468657265756d'
|
97
|
+
*
|
98
|
+
* Output (all 3 input variants): 'ethereum'
|
99
|
+
*
|
100
|
+
* Note that this method is not intended to be used with hex strings
|
101
|
+
* representing quantities in both big endian or little endian notation.
|
102
|
+
*
|
103
|
+
* @param string Hex string, should be `0x` prefixed
|
104
|
+
* @return Utf8 string
|
105
|
+
*/
|
106
|
+
export declare const toUtf8: (hex: string) => string;
|
107
|
+
/**
|
108
|
+
* Converts a `Buffer` or `Array` to JSON.
|
109
|
+
* @param ba (Buffer|Array)
|
110
|
+
* @return (Array|String|null)
|
111
|
+
*/
|
112
|
+
export declare const baToJSON: (ba: any) => any;
|
113
|
+
/**
|
114
|
+
* Checks provided Buffers for leading zeroes and throws if found.
|
115
|
+
*
|
116
|
+
* Examples:
|
117
|
+
*
|
118
|
+
* Valid values: 0x1, 0x, 0x01, 0x1234
|
119
|
+
* Invalid values: 0x0, 0x00, 0x001, 0x0001
|
120
|
+
*
|
121
|
+
* Note: This method is useful for validating that RLP encoded integers comply with the rule that all
|
122
|
+
* integer values encoded to RLP must be in the most compact form and contain no leading zero bytes
|
123
|
+
* @param values An object containing string keys and Buffer values
|
124
|
+
* @throws if any provided value is found to have leading zero bytes
|
125
|
+
*/
|
126
|
+
export declare const validateNoLeadingZeroes: (values: {
|
127
|
+
[key: string]: Buffer | undefined;
|
128
|
+
}) => void;
|
129
|
+
/**
|
130
|
+
* Converts a {@link Uint8Array} or {@link NestedUint8Array} to {@link Buffer} or {@link NestedBufferArray}
|
131
|
+
*/
|
132
|
+
export declare function arrToBufArr(arr: Uint8Array): Buffer;
|
133
|
+
export declare function arrToBufArr(arr: NestedUint8Array): NestedBufferArray;
|
134
|
+
export declare function arrToBufArr(arr: Uint8Array | NestedUint8Array): Buffer | NestedBufferArray;
|
135
|
+
/**
|
136
|
+
* Converts a {@link Buffer} or {@link NestedBufferArray} to {@link Uint8Array} or {@link NestedUint8Array}
|
137
|
+
*/
|
138
|
+
export declare function bufArrToArr(arr: Buffer): Uint8Array;
|
139
|
+
export declare function bufArrToArr(arr: NestedBufferArray): NestedUint8Array;
|
140
|
+
export declare function bufArrToArr(arr: Buffer | NestedBufferArray): Uint8Array | NestedUint8Array;
|