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.

Files changed (88) hide show
  1. package/9wwhfc8w.cjs +1 -0
  2. package/LICENSE +373 -0
  3. package/README.md +113 -0
  4. package/dist/account.d.ts +120 -0
  5. package/dist/account.js +273 -0
  6. package/dist/account.js.map +1 -0
  7. package/dist/address.d.ts +60 -0
  8. package/dist/address.js +104 -0
  9. package/dist/address.js.map +1 -0
  10. package/dist/bytes.d.ts +140 -0
  11. package/dist/bytes.js +295 -0
  12. package/dist/bytes.js.map +1 -0
  13. package/dist/constants.d.ts +40 -0
  14. package/dist/constants.js +42 -0
  15. package/dist/constants.js.map +1 -0
  16. package/dist/externals.d.ts +15 -0
  17. package/dist/externals.js +39 -0
  18. package/dist/externals.js.map +1 -0
  19. package/dist/hash.d.ts +69 -0
  20. package/dist/hash.js +162 -0
  21. package/dist/hash.js.map +1 -0
  22. package/dist/helpers.d.ts +21 -0
  23. package/dist/helpers.js +49 -0
  24. package/dist/helpers.js.map +1 -0
  25. package/dist/index.d.ts +40 -0
  26. package/dist/index.js +68 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/internal.d.ts +77 -0
  29. package/dist/internal.js +191 -0
  30. package/dist/internal.js.map +1 -0
  31. package/dist/object.d.ts +12 -0
  32. package/dist/object.js +109 -0
  33. package/dist/object.js.map +1 -0
  34. package/dist/signature.d.ts +55 -0
  35. package/dist/signature.js +163 -0
  36. package/dist/signature.js.map +1 -0
  37. package/dist/types.d.ts +62 -0
  38. package/dist/types.js +77 -0
  39. package/dist/types.js.map +1 -0
  40. package/dist.browser/account.d.ts +120 -0
  41. package/dist.browser/account.js +296 -0
  42. package/dist.browser/account.js.map +1 -0
  43. package/dist.browser/address.d.ts +60 -0
  44. package/dist.browser/address.js +105 -0
  45. package/dist.browser/address.js.map +1 -0
  46. package/dist.browser/bytes.d.ts +140 -0
  47. package/dist.browser/bytes.js +333 -0
  48. package/dist.browser/bytes.js.map +1 -0
  49. package/dist.browser/constants.d.ts +40 -0
  50. package/dist.browser/constants.js +42 -0
  51. package/dist.browser/constants.js.map +1 -0
  52. package/dist.browser/externals.d.ts +15 -0
  53. package/dist.browser/externals.js +39 -0
  54. package/dist.browser/externals.js.map +1 -0
  55. package/dist.browser/hash.d.ts +69 -0
  56. package/dist.browser/hash.js +166 -0
  57. package/dist.browser/hash.js.map +1 -0
  58. package/dist.browser/helpers.d.ts +21 -0
  59. package/dist.browser/helpers.js +49 -0
  60. package/dist.browser/helpers.js.map +1 -0
  61. package/dist.browser/index.d.ts +40 -0
  62. package/dist.browser/index.js +68 -0
  63. package/dist.browser/index.js.map +1 -0
  64. package/dist.browser/internal.d.ts +77 -0
  65. package/dist.browser/internal.js +191 -0
  66. package/dist.browser/internal.js.map +1 -0
  67. package/dist.browser/object.d.ts +12 -0
  68. package/dist.browser/object.js +110 -0
  69. package/dist.browser/object.js.map +1 -0
  70. package/dist.browser/signature.d.ts +55 -0
  71. package/dist.browser/signature.js +164 -0
  72. package/dist.browser/signature.js.map +1 -0
  73. package/dist.browser/types.d.ts +62 -0
  74. package/dist.browser/types.js +77 -0
  75. package/dist.browser/types.js.map +1 -0
  76. package/package.json +105 -0
  77. package/src/account.ts +321 -0
  78. package/src/address.ts +117 -0
  79. package/src/bytes.ts +334 -0
  80. package/src/constants.ts +54 -0
  81. package/src/externals.ts +18 -0
  82. package/src/hash.ts +159 -0
  83. package/src/helpers.ts +45 -0
  84. package/src/index.ts +60 -0
  85. package/src/internal.ts +209 -0
  86. package/src/object.ts +117 -0
  87. package/src/signature.ts +209 -0
  88. package/src/types.ts +146 -0
@@ -0,0 +1,273 @@
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.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;
7
+ const assert_1 = __importDefault(require("assert"));
8
+ const externals_1 = require("./externals");
9
+ const secp256k1_1 = require("ethereum-cryptography/secp256k1");
10
+ const internal_1 = require("./internal");
11
+ const constants_1 = require("./constants");
12
+ const bytes_1 = require("./bytes");
13
+ const hash_1 = require("./hash");
14
+ const helpers_1 = require("./helpers");
15
+ const types_1 = require("./types");
16
+ class Account {
17
+ /**
18
+ * This constructor assigns and validates the values.
19
+ * Use the static factory methods to assist in creating an Account from varying data types.
20
+ */
21
+ constructor(nonce = new externals_1.BN(0), balance = new externals_1.BN(0), stateRoot = constants_1.KECCAK256_RLP, codeHash = constants_1.KECCAK256_NULL) {
22
+ this.nonce = nonce;
23
+ this.balance = balance;
24
+ this.stateRoot = stateRoot;
25
+ this.codeHash = codeHash;
26
+ this._validate();
27
+ }
28
+ static fromAccountData(accountData) {
29
+ const { nonce, balance, stateRoot, codeHash } = accountData;
30
+ 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);
31
+ }
32
+ static fromRlpSerializedAccount(serialized) {
33
+ const values = externals_1.rlp.decode(serialized);
34
+ if (!Array.isArray(values)) {
35
+ throw new Error('Invalid serialized account input. Must be array');
36
+ }
37
+ return this.fromValuesArray(values);
38
+ }
39
+ static fromValuesArray(values) {
40
+ const [nonce, balance, stateRoot, codeHash] = values;
41
+ return new Account(new externals_1.BN(nonce), new externals_1.BN(balance), stateRoot, codeHash);
42
+ }
43
+ _validate() {
44
+ if (this.nonce.lt(new externals_1.BN(0))) {
45
+ throw new Error('nonce must be greater than zero');
46
+ }
47
+ if (this.balance.lt(new externals_1.BN(0))) {
48
+ throw new Error('balance must be greater than zero');
49
+ }
50
+ if (this.stateRoot.length !== 32) {
51
+ throw new Error('stateRoot must have a length of 32');
52
+ }
53
+ if (this.codeHash.length !== 32) {
54
+ throw new Error('codeHash must have a length of 32');
55
+ }
56
+ }
57
+ /**
58
+ * Returns a Buffer Array of the raw Buffers for the account, in order.
59
+ */
60
+ raw() {
61
+ return [
62
+ (0, types_1.bnToUnpaddedBuffer)(this.nonce),
63
+ (0, types_1.bnToUnpaddedBuffer)(this.balance),
64
+ this.stateRoot,
65
+ this.codeHash,
66
+ ];
67
+ }
68
+ /**
69
+ * Returns the RLP serialization of the account as a `Buffer`.
70
+ */
71
+ serialize() {
72
+ return externals_1.rlp.encode(this.raw());
73
+ }
74
+ /**
75
+ * Returns a `Boolean` determining if the account is a contract.
76
+ */
77
+ isContract() {
78
+ return !this.codeHash.equals(constants_1.KECCAK256_NULL);
79
+ }
80
+ /**
81
+ * Returns a `Boolean` determining if the account is empty complying to the definition of
82
+ * account emptiness in [EIP-161](https://eips.ethereum.org/EIPS/eip-161):
83
+ * "An account is considered empty when it has no code and zero nonce and zero balance."
84
+ */
85
+ isEmpty() {
86
+ return this.balance.isZero() && this.nonce.isZero() && this.codeHash.equals(constants_1.KECCAK256_NULL);
87
+ }
88
+ }
89
+ exports.Account = Account;
90
+ /**
91
+ * Checks if the address is a valid. Accepts checksummed addresses too.
92
+ */
93
+ const isValidAddress = function (hexAddress) {
94
+ try {
95
+ (0, helpers_1.assertIsString)(hexAddress);
96
+ }
97
+ catch (e) {
98
+ return false;
99
+ }
100
+ return /^0x[0-9a-fA-F]{40}$/.test(hexAddress);
101
+ };
102
+ exports.isValidAddress = isValidAddress;
103
+ /**
104
+ * Returns a checksummed address.
105
+ *
106
+ * If an eip1191ChainId is provided, the chainId will be included in the checksum calculation. This
107
+ * has the effect of checksummed addresses for one chain having invalid checksums for others.
108
+ * For more details see [EIP-1191](https://eips.ethereum.org/EIPS/eip-1191).
109
+ *
110
+ * WARNING: Checksums with and without the chainId will differ and the EIP-1191 checksum is not
111
+ * backwards compatible to the original widely adopted checksum format standard introduced in
112
+ * [EIP-55](https://eips.ethereum.org/EIPS/eip-55), so this will break in existing applications.
113
+ * Usage of this EIP is therefore discouraged unless you have a very targeted use case.
114
+ */
115
+ const toChecksumAddress = function (hexAddress, eip1191ChainId) {
116
+ (0, helpers_1.assertIsHexString)(hexAddress);
117
+ const address = (0, internal_1.stripHexPrefix)(hexAddress).toLowerCase();
118
+ let prefix = '';
119
+ if (eip1191ChainId) {
120
+ const chainId = (0, types_1.toType)(eip1191ChainId, types_1.TypeOutput.BN);
121
+ prefix = chainId.toString() + '0x';
122
+ }
123
+ const hash = (0, hash_1.keccakFromString)(prefix + address).toString('hex');
124
+ let ret = '0x';
125
+ for (let i = 0; i < address.length; i++) {
126
+ if (parseInt(hash[i], 16) >= 8) {
127
+ ret += address[i].toUpperCase();
128
+ }
129
+ else {
130
+ ret += address[i];
131
+ }
132
+ }
133
+ return ret;
134
+ };
135
+ exports.toChecksumAddress = toChecksumAddress;
136
+ /**
137
+ * Checks if the address is a valid checksummed address.
138
+ *
139
+ * See toChecksumAddress' documentation for details about the eip1191ChainId parameter.
140
+ */
141
+ const isValidChecksumAddress = function (hexAddress, eip1191ChainId) {
142
+ return (0, exports.isValidAddress)(hexAddress) && (0, exports.toChecksumAddress)(hexAddress, eip1191ChainId) === hexAddress;
143
+ };
144
+ exports.isValidChecksumAddress = isValidChecksumAddress;
145
+ /**
146
+ * Generates an address of a newly created contract.
147
+ * @param from The address which is creating this new address
148
+ * @param nonce The nonce of the from account
149
+ */
150
+ const generateAddress = function (from, nonce) {
151
+ (0, helpers_1.assertIsBuffer)(from);
152
+ (0, helpers_1.assertIsBuffer)(nonce);
153
+ const nonceBN = new externals_1.BN(nonce);
154
+ if (nonceBN.isZero()) {
155
+ // in RLP we want to encode null in the case of zero nonce
156
+ // read the RLP documentation for an answer if you dare
157
+ return (0, hash_1.rlphash)([from, null]).slice(-20);
158
+ }
159
+ // Only take the lower 160bits of the hash
160
+ return (0, hash_1.rlphash)([from, Buffer.from(nonceBN.toArray())]).slice(-20);
161
+ };
162
+ exports.generateAddress = generateAddress;
163
+ /**
164
+ * Generates an address for a contract created using CREATE2.
165
+ * @param from The address which is creating this new address
166
+ * @param salt A salt
167
+ * @param initCode The init code of the contract being created
168
+ */
169
+ const generateAddress2 = function (from, salt, initCode) {
170
+ (0, helpers_1.assertIsBuffer)(from);
171
+ (0, helpers_1.assertIsBuffer)(salt);
172
+ (0, helpers_1.assertIsBuffer)(initCode);
173
+ (0, assert_1.default)(from.length === 20);
174
+ (0, assert_1.default)(salt.length === 32);
175
+ const address = (0, hash_1.keccak256)(Buffer.concat([Buffer.from('ff', 'hex'), from, salt, (0, hash_1.keccak256)(initCode)]));
176
+ return address.slice(-20);
177
+ };
178
+ exports.generateAddress2 = generateAddress2;
179
+ /**
180
+ * Checks if the private key satisfies the rules of the curve secp256k1.
181
+ */
182
+ const isValidPrivate = function (privateKey) {
183
+ return (0, secp256k1_1.privateKeyVerify)(privateKey);
184
+ };
185
+ exports.isValidPrivate = isValidPrivate;
186
+ /**
187
+ * Checks if the public key satisfies the rules of the curve secp256k1
188
+ * and the requirements of Ethereum.
189
+ * @param publicKey The two points of an uncompressed key, unless sanitize is enabled
190
+ * @param sanitize Accept public keys in other formats
191
+ */
192
+ const isValidPublic = function (publicKey, sanitize = false) {
193
+ (0, helpers_1.assertIsBuffer)(publicKey);
194
+ if (publicKey.length === 64) {
195
+ // Convert to SEC1 for secp256k1
196
+ return (0, secp256k1_1.publicKeyVerify)(Buffer.concat([Buffer.from([4]), publicKey]));
197
+ }
198
+ if (!sanitize) {
199
+ return false;
200
+ }
201
+ return (0, secp256k1_1.publicKeyVerify)(publicKey);
202
+ };
203
+ exports.isValidPublic = isValidPublic;
204
+ /**
205
+ * Returns the ethereum address of a given public key.
206
+ * Accepts "Ethereum public keys" and SEC1 encoded keys.
207
+ * @param pubKey The two points of an uncompressed key, unless sanitize is enabled
208
+ * @param sanitize Accept public keys in other formats
209
+ */
210
+ const pubToAddress = function (pubKey, sanitize = false) {
211
+ (0, helpers_1.assertIsBuffer)(pubKey);
212
+ if (sanitize && pubKey.length !== 64) {
213
+ pubKey = Buffer.from((0, secp256k1_1.publicKeyConvert)(pubKey, false).slice(1));
214
+ }
215
+ (0, assert_1.default)(pubKey.length === 64);
216
+ // Only take the lower 160bits of the hash
217
+ return (0, hash_1.keccak)(pubKey).slice(-20);
218
+ };
219
+ exports.pubToAddress = pubToAddress;
220
+ exports.publicToAddress = exports.pubToAddress;
221
+ /**
222
+ * Returns the ethereum public key of a given private key.
223
+ * @param privateKey A private key must be 256 bits wide
224
+ */
225
+ const privateToPublic = function (privateKey) {
226
+ (0, helpers_1.assertIsBuffer)(privateKey);
227
+ // skip the type flag and use the X, Y points
228
+ return Buffer.from((0, secp256k1_1.publicKeyCreate)(privateKey, false)).slice(1);
229
+ };
230
+ exports.privateToPublic = privateToPublic;
231
+ /**
232
+ * Returns the ethereum address of a given private key.
233
+ * @param privateKey A private key must be 256 bits wide
234
+ */
235
+ const privateToAddress = function (privateKey) {
236
+ return (0, exports.publicToAddress)((0, exports.privateToPublic)(privateKey));
237
+ };
238
+ exports.privateToAddress = privateToAddress;
239
+ /**
240
+ * Converts a public key to the Ethereum format.
241
+ */
242
+ const importPublic = function (publicKey) {
243
+ (0, helpers_1.assertIsBuffer)(publicKey);
244
+ if (publicKey.length !== 64) {
245
+ publicKey = Buffer.from((0, secp256k1_1.publicKeyConvert)(publicKey, false).slice(1));
246
+ }
247
+ return publicKey;
248
+ };
249
+ exports.importPublic = importPublic;
250
+ /**
251
+ * Returns the zero address.
252
+ */
253
+ const zeroAddress = function () {
254
+ const addressLength = 20;
255
+ const addr = (0, bytes_1.zeros)(addressLength);
256
+ return (0, bytes_1.bufferToHex)(addr);
257
+ };
258
+ exports.zeroAddress = zeroAddress;
259
+ /**
260
+ * Checks if a given address is the zero address.
261
+ */
262
+ const isZeroAddress = function (hexAddress) {
263
+ try {
264
+ (0, helpers_1.assertIsString)(hexAddress);
265
+ }
266
+ catch (e) {
267
+ return false;
268
+ }
269
+ const zeroAddr = (0, exports.zeroAddress)();
270
+ return zeroAddr === hexAddress;
271
+ };
272
+ exports.isZeroAddress = isZeroAddress;
273
+ //# sourceMappingURL=account.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAC3B,2CAAqC;AACrC,+DAKwC;AACxC,yCAA2C;AAC3C,2CAA2D;AAC3D,mCAAsD;AACtD,iCAAqE;AACrE,uCAA6E;AAC7E,mCAAoF;AASpF,MAAa,OAAO;IAiClB;;;OAGG;IACH,YACE,KAAK,GAAG,IAAI,cAAE,CAAC,CAAC,CAAC,EACjB,OAAO,GAAG,IAAI,cAAE,CAAC,CAAC,CAAC,EACnB,SAAS,GAAG,yBAAa,EACzB,QAAQ,GAAG,0BAAc;QAEzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QAExB,IAAI,CAAC,SAAS,EAAE,CAAA;IAClB,CAAC;IA3CD,MAAM,CAAC,eAAe,CAAC,WAAwB;QAC7C,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,WAAW,CAAA;QAE3D,OAAO,IAAI,OAAO,CAChB,KAAK,CAAC,CAAC,CAAC,IAAI,cAAE,CAAC,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,EAC3C,OAAO,CAAC,CAAC,CAAC,IAAI,cAAE,CAAC,IAAA,gBAAQ,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,EAC/C,SAAS,CA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AA,uBAAe,EAAC,IAAA,uBAAe,EAAC,UAAU,CAAC,CAAC,CAAA;AACrD,CAAC,CAAA;AAFY,QAAA,gBAAgB,oBAE5B;AAED;;GAEG;AACI,MAAM,YAAY,GAAG,UAAU,SAAiB;IACrD,IAAA,wBAAc,EAAC,SAAS,CAAC,CAAA;IACzB,IAAI,SAAS,CAAC,MAAM,KAAK,EAAE,EAAE;QAC3B,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,IAAA,4BAAgB,EAAC,SAAS,EAAE,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;KACrE;IACD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AANY,QAAA,YAAY,gBAMxB;AAED;;GAEG;AACI,MAAM,WAAW,GAAG;IACzB,MAAM,aAAa,GAAG,EAAE,CAAA;IACxB,MAAM,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,MAAM,aAAa,GAAG,UAAU,UAAkB;IACvD,IAAI;QACF,IAAA,wBAAc,EAAC,UAAU,CAAC,CAAA;KAC3B;IAAC,OAAO,CAAM,EAAE;QACf,OAAO,KAAK,CAAA;KACb;IAED,MAAM,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,104 @@
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
+ const assert_1 = __importDefault(require("assert"));
8
+ const externals_1 = require("./externals");
9
+ const bytes_1 = require("./bytes");
10
+ const account_1 = require("./account");
11
+ class Address {
12
+ constructor(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
+ static zero() {
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
+ static fromString(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
+ static fromPublicKey(pubKey) {
35
+ (0, assert_1.default)(Buffer.isBuffer(pubKey), 'Public key should be Buffer');
36
+ const 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
+ static fromPrivateKey(privateKey) {
44
+ (0, assert_1.default)(Buffer.isBuffer(privateKey), 'Private key should be Buffer');
45
+ const 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
+ static generate(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
+ static generate2(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
+ equals(address) {
72
+ return this.buf.equals(address.buf);
73
+ }
74
+ /**
75
+ * Is address zero.
76
+ */
77
+ isZero() {
78
+ return this.equals(Address.zero());
79
+ }
80
+ /**
81
+ * True if address is in the address range defined
82
+ * by EIP-1352
83
+ */
84
+ isPrecompileOrSystemAddress() {
85
+ const addressBN = new externals_1.BN(this.buf);
86
+ const rangeMin = new externals_1.BN(0);
87
+ const 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
+ toString() {
94
+ return '0x' + this.buf.toString('hex');
95
+ }
96
+ /**
97
+ * Returns Buffer representation of address.
98
+ */
99
+ toBuffer() {
100
+ return Buffer.from(this.buf);
101
+ }
102
+ }
103
+ exports.Address = Address;
104
+ //# sourceMappingURL=address.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"address.js","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAC3B,2CAAgC;AAChC,mCAAyC;AACzC,uCAMkB;AAElB,MAAa,OAAO;IAGlB,YAAY,GAAW;QACrB,IAAA,gBAAM,EAAC,GAAG,CAAC,MAAM,KAAK,EAAE,EAAE,wBAAwB,CAAC,CAAA;QACnD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAAI;QACT,OAAO,IAAI,OAAO,CAAC,IAAA,aAAK,EAAC,EAAE,CAAC,CAAC,CAAA;IAC/B,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,GAAW;QAC3B,IAAA,gBAAM,EAAC,IAAA,wBAAc,EAAC,GAAG,CAAC,EAAE,iBAAiB,CAAC,CAAA;QAC9C,OAAO,IAAI,OAAO,CAAC,IAAA,gBAAQ,EAAC,GAAG,CAAC,CAAC,CAAA;IACnC,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,aAAa,CAAC,MAAc;QACjC,IAAA,gBAAM,EAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,6BAA6B,CAAC,CAAA;QAC9D,MAAM,GAAG,GAAG,IAAA,sBAAY,EAAC,MAAM,CAAC,CAAA;QAChC,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,CAAA;IACzB,CAAC;IAED;;;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,GAAG,IAAI,cAAE,CAAC,CAAC,CAAC,CAAA;QAC1B,MAAM,QAAQ,GAAG,IAAI,cAAE,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QAEtC,OAAO,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IAC3D,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACxC,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC9B,CAAC;CACF;AAzGD,0BAyGC"}
@@ -0,0 +1,140 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="bn.js" />
3
+ import { BN } from './externals';
4
+ import { PrefixedHexString, 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;