viem 0.0.0-main.20240510T172655 → 0.0.0-main.20240511T054305
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/_cjs/errors/version.js +1 -1
- package/_cjs/utils/address/getAddress.js +8 -2
- package/_cjs/utils/address/getAddress.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/utils/address/getAddress.js +31 -3
- package/_esm/utils/address/getAddress.js.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/utils/address/getAddress.d.ts +26 -2
- package/_types/utils/address/getAddress.d.ts.map +1 -1
- package/errors/version.ts +1 -1
- package/package.json +1 -1
- package/utils/address/getAddress.ts +33 -2
package/_cjs/errors/version.js
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getAddress = exports.checksumAddress = void 0;
|
3
|
+
exports.getAddress = exports.checksumAddress = exports.checksumAddressCache = void 0;
|
4
4
|
const address_js_1 = require("../../errors/address.js");
|
5
5
|
const toBytes_js_1 = require("../encoding/toBytes.js");
|
6
6
|
const keccak256_js_1 = require("../hash/keccak256.js");
|
7
|
+
const lru_js_1 = require("../lru.js");
|
7
8
|
const isAddress_js_1 = require("./isAddress.js");
|
9
|
+
exports.checksumAddressCache = new lru_js_1.LruMap(8192);
|
8
10
|
function checksumAddress(address_, chainId) {
|
11
|
+
if (exports.checksumAddressCache.has(`${address_}.${chainId}`))
|
12
|
+
return exports.checksumAddressCache.get(`${address_}.${chainId}`);
|
9
13
|
const hexAddress = chainId
|
10
14
|
? `${chainId}${address_.toLowerCase()}`
|
11
15
|
: address_.substring(2).toLowerCase();
|
@@ -19,7 +23,9 @@ function checksumAddress(address_, chainId) {
|
|
19
23
|
address[i + 1] = address[i + 1].toUpperCase();
|
20
24
|
}
|
21
25
|
}
|
22
|
-
|
26
|
+
const result = `0x${address.join('')}`;
|
27
|
+
exports.checksumAddressCache.set(`${address_}.${chainId}`, result);
|
28
|
+
return result;
|
23
29
|
}
|
24
30
|
exports.checksumAddress = checksumAddress;
|
25
31
|
function getAddress(address, chainId) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getAddress.js","sourceRoot":"","sources":["../../../utils/address/getAddress.ts"],"names":[],"mappings":";;;AAEA,wDAA6D;AAE7D,uDAG+B;AAC/B,uDAAyE;AACzE,iDAAmE;
|
1
|
+
{"version":3,"file":"getAddress.js","sourceRoot":"","sources":["../../../utils/address/getAddress.ts"],"names":[],"mappings":";;;AAEA,wDAA6D;AAE7D,uDAG+B;AAC/B,uDAAyE;AACzE,sCAAkC;AAClC,iDAAmE;AAEtD,QAAA,oBAAoB,GAAiB,IAAI,eAAM,CAAU,IAAI,CAAC,CAAA;AAO3E,SAAgB,eAAe,CAC7B,QAAiB,EAWjB,OAA4B;IAE5B,IAAI,4BAAoB,CAAC,GAAG,CAAC,GAAG,QAAQ,IAAI,OAAO,EAAE,CAAC;QACpD,OAAO,4BAAoB,CAAC,GAAG,CAAC,GAAG,QAAQ,IAAI,OAAO,EAAE,CAAE,CAAA;IAE5D,MAAM,UAAU,GAAG,OAAO;QACxB,CAAC,CAAC,GAAG,OAAO,GAAG,QAAQ,CAAC,WAAW,EAAE,EAAE;QACvC,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;IACvC,MAAM,IAAI,GAAG,IAAA,wBAAS,EAAC,IAAA,0BAAa,EAAC,UAAU,CAAC,EAAE,OAAO,CAAC,CAAA;IAE1D,MAAM,OAAO,GAAG,CACd,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CACnE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IACX,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/B,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;YACzC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;QACvC,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YACjD,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;QAC/C,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,EAAW,CAAA;IAC/C,4BAAoB,CAAC,GAAG,CAAC,GAAG,QAAQ,IAAI,OAAO,EAAE,EAAE,MAAM,CAAC,CAAA;IAC1D,OAAO,MAAM,CAAA;AACf,CAAC;AArCD,0CAqCC;AAOD,SAAgB,UAAU,CACxB,OAAe,EAWf,OAAgB;IAEhB,IAAI,CAAC,IAAA,wBAAS,EAAC,OAAO,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QACxC,MAAM,IAAI,gCAAmB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;IAC5C,OAAO,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AAC1C,CAAC;AAjBD,gCAiBC"}
|
package/_esm/errors/version.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export const version = '0.0.0-main.
|
1
|
+
export const version = '0.0.0-main.20240511T054305';
|
2
2
|
//# sourceMappingURL=version.js.map
|
@@ -1,8 +1,23 @@
|
|
1
1
|
import { InvalidAddressError } from '../../errors/address.js';
|
2
2
|
import { stringToBytes, } from '../encoding/toBytes.js';
|
3
3
|
import { keccak256 } from '../hash/keccak256.js';
|
4
|
+
import { LruMap } from '../lru.js';
|
4
5
|
import { isAddress } from './isAddress.js';
|
5
|
-
export
|
6
|
+
export const checksumAddressCache = /*#__PURE__*/ new LruMap(8192);
|
7
|
+
export function checksumAddress(address_,
|
8
|
+
/**
|
9
|
+
* Warning: EIP-1191 checksum addresses are generally not backwards compatible with the
|
10
|
+
* wider Ethereum ecosystem, meaning it will break when validated against an application/tool
|
11
|
+
* that relies on EIP-55 checksum encoding (checksum without chainId).
|
12
|
+
*
|
13
|
+
* It is highly recommended to not use this feature unless you
|
14
|
+
* know what you are doing.
|
15
|
+
*
|
16
|
+
* See more: https://github.com/ethereum/EIPs/issues/1121
|
17
|
+
*/
|
18
|
+
chainId) {
|
19
|
+
if (checksumAddressCache.has(`${address_}.${chainId}`))
|
20
|
+
return checksumAddressCache.get(`${address_}.${chainId}`);
|
6
21
|
const hexAddress = chainId
|
7
22
|
? `${chainId}${address_.toLowerCase()}`
|
8
23
|
: address_.substring(2).toLowerCase();
|
@@ -16,9 +31,22 @@ export function checksumAddress(address_, chainId) {
|
|
16
31
|
address[i + 1] = address[i + 1].toUpperCase();
|
17
32
|
}
|
18
33
|
}
|
19
|
-
|
34
|
+
const result = `0x${address.join('')}`;
|
35
|
+
checksumAddressCache.set(`${address_}.${chainId}`, result);
|
36
|
+
return result;
|
20
37
|
}
|
21
|
-
export function getAddress(address,
|
38
|
+
export function getAddress(address,
|
39
|
+
/**
|
40
|
+
* Warning: EIP-1191 checksum addresses are generally not backwards compatible with the
|
41
|
+
* wider Ethereum ecosystem, meaning it will break when validated against an application/tool
|
42
|
+
* that relies on EIP-55 checksum encoding (checksum without chainId).
|
43
|
+
*
|
44
|
+
* It is highly recommended to not use this feature unless you
|
45
|
+
* know what you are doing.
|
46
|
+
*
|
47
|
+
* See more: https://github.com/ethereum/EIPs/issues/1121
|
48
|
+
*/
|
49
|
+
chainId) {
|
22
50
|
if (!isAddress(address, { strict: false }))
|
23
51
|
throw new InvalidAddressError({ address });
|
24
52
|
return checksumAddress(address, chainId);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getAddress.js","sourceRoot":"","sources":["../../../utils/address/getAddress.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAE7D,OAAO,EAEL,aAAa,GACd,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAA2B,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACzE,OAAO,EAA2B,SAAS,EAAE,MAAM,gBAAgB,CAAA;
|
1
|
+
{"version":3,"file":"getAddress.js","sourceRoot":"","sources":["../../../utils/address/getAddress.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAE7D,OAAO,EAEL,aAAa,GACd,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAA2B,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EAA2B,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAEnE,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAC,IAAI,MAAM,CAAU,IAAI,CAAC,CAAA;AAO3E,MAAM,UAAU,eAAe,CAC7B,QAAiB;AACjB;;;;;;;;;GASG;AACH,OAA4B;IAE5B,IAAI,oBAAoB,CAAC,GAAG,CAAC,GAAG,QAAQ,IAAI,OAAO,EAAE,CAAC;QACpD,OAAO,oBAAoB,CAAC,GAAG,CAAC,GAAG,QAAQ,IAAI,OAAO,EAAE,CAAE,CAAA;IAE5D,MAAM,UAAU,GAAG,OAAO;QACxB,CAAC,CAAC,GAAG,OAAO,GAAG,QAAQ,CAAC,WAAW,EAAE,EAAE;QACvC,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;IACvC,MAAM,IAAI,GAAG,SAAS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AAO,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AAC1C,CAAC"}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export declare const version = "0.0.0-main.
|
1
|
+
export declare const version = "0.0.0-main.20240511T054305";
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
@@ -2,9 +2,33 @@ import type { Address } from 'abitype';
|
|
2
2
|
import type { ErrorType } from '../../errors/utils.js';
|
3
3
|
import { type StringToBytesErrorType } from '../encoding/toBytes.js';
|
4
4
|
import { type Keccak256ErrorType } from '../hash/keccak256.js';
|
5
|
+
import { LruMap } from '../lru.js';
|
5
6
|
import { type IsAddressErrorType } from './isAddress.js';
|
7
|
+
export declare const checksumAddressCache: LruMap<`0x${string}`>;
|
6
8
|
export type ChecksumAddressErrorType = Keccak256ErrorType | StringToBytesErrorType | ErrorType;
|
7
|
-
export declare function checksumAddress(address_: Address,
|
9
|
+
export declare function checksumAddress(address_: Address,
|
10
|
+
/**
|
11
|
+
* Warning: EIP-1191 checksum addresses are generally not backwards compatible with the
|
12
|
+
* wider Ethereum ecosystem, meaning it will break when validated against an application/tool
|
13
|
+
* that relies on EIP-55 checksum encoding (checksum without chainId).
|
14
|
+
*
|
15
|
+
* It is highly recommended to not use this feature unless you
|
16
|
+
* know what you are doing.
|
17
|
+
*
|
18
|
+
* See more: https://github.com/ethereum/EIPs/issues/1121
|
19
|
+
*/
|
20
|
+
chainId?: number | undefined): Address;
|
8
21
|
export type GetAddressErrorType = ChecksumAddressErrorType | IsAddressErrorType | ErrorType;
|
9
|
-
export declare function getAddress(address: string,
|
22
|
+
export declare function getAddress(address: string,
|
23
|
+
/**
|
24
|
+
* Warning: EIP-1191 checksum addresses are generally not backwards compatible with the
|
25
|
+
* wider Ethereum ecosystem, meaning it will break when validated against an application/tool
|
26
|
+
* that relies on EIP-55 checksum encoding (checksum without chainId).
|
27
|
+
*
|
28
|
+
* It is highly recommended to not use this feature unless you
|
29
|
+
* know what you are doing.
|
30
|
+
*
|
31
|
+
* See more: https://github.com/ethereum/EIPs/issues/1121
|
32
|
+
*/
|
33
|
+
chainId?: number): Address;
|
10
34
|
//# sourceMappingURL=getAddress.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getAddress.d.ts","sourceRoot":"","sources":["../../../utils/address/getAddress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAGtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EACL,KAAK,sBAAsB,EAE5B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,KAAK,kBAAkB,EAAa,MAAM,sBAAsB,CAAA;AACzE,OAAO,EAAE,KAAK,kBAAkB,EAAa,MAAM,gBAAgB,CAAA;AAEnE,MAAM,MAAM,wBAAwB,GAChC,kBAAkB,GAClB,sBAAsB,GACtB,SAAS,CAAA;AAEb,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,OAAO,
|
1
|
+
{"version":3,"file":"getAddress.d.ts","sourceRoot":"","sources":["../../../utils/address/getAddress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAGtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EACL,KAAK,sBAAsB,EAE5B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,KAAK,kBAAkB,EAAa,MAAM,sBAAsB,CAAA;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EAAE,KAAK,kBAAkB,EAAa,MAAM,gBAAgB,CAAA;AAEnE,eAAO,MAAM,oBAAoB,uBAA0C,CAAA;AAE3E,MAAM,MAAM,wBAAwB,GAChC,kBAAkB,GAClB,sBAAsB,GACtB,SAAS,CAAA;AAEb,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,OAAO;AACjB;;;;;;;;;GASG;AACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAC3B,OAAO,CAwBT;AAED,MAAM,MAAM,mBAAmB,GAC3B,wBAAwB,GACxB,kBAAkB,GAClB,SAAS,CAAA;AAEb,wBAAgB,UAAU,CACxB,OAAO,EAAE,MAAM;AACf;;;;;;;;;GASG;AACH,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAIT"}
|
package/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '0.0.0-main.
|
1
|
+
export const version = '0.0.0-main.20240511T054305'
|
package/package.json
CHANGED
@@ -7,8 +7,11 @@ import {
|
|
7
7
|
stringToBytes,
|
8
8
|
} from '../encoding/toBytes.js'
|
9
9
|
import { type Keccak256ErrorType, keccak256 } from '../hash/keccak256.js'
|
10
|
+
import { LruMap } from '../lru.js'
|
10
11
|
import { type IsAddressErrorType, isAddress } from './isAddress.js'
|
11
12
|
|
13
|
+
export const checksumAddressCache = /*#__PURE__*/ new LruMap<Address>(8192)
|
14
|
+
|
12
15
|
export type ChecksumAddressErrorType =
|
13
16
|
| Keccak256ErrorType
|
14
17
|
| StringToBytesErrorType
|
@@ -16,8 +19,21 @@ export type ChecksumAddressErrorType =
|
|
16
19
|
|
17
20
|
export function checksumAddress(
|
18
21
|
address_: Address,
|
22
|
+
/**
|
23
|
+
* Warning: EIP-1191 checksum addresses are generally not backwards compatible with the
|
24
|
+
* wider Ethereum ecosystem, meaning it will break when validated against an application/tool
|
25
|
+
* that relies on EIP-55 checksum encoding (checksum without chainId).
|
26
|
+
*
|
27
|
+
* It is highly recommended to not use this feature unless you
|
28
|
+
* know what you are doing.
|
29
|
+
*
|
30
|
+
* See more: https://github.com/ethereum/EIPs/issues/1121
|
31
|
+
*/
|
19
32
|
chainId?: number | undefined,
|
20
33
|
): Address {
|
34
|
+
if (checksumAddressCache.has(`${address_}.${chainId}`))
|
35
|
+
return checksumAddressCache.get(`${address_}.${chainId}`)!
|
36
|
+
|
21
37
|
const hexAddress = chainId
|
22
38
|
? `${chainId}${address_.toLowerCase()}`
|
23
39
|
: address_.substring(2).toLowerCase()
|
@@ -35,7 +51,9 @@ export function checksumAddress(
|
|
35
51
|
}
|
36
52
|
}
|
37
53
|
|
38
|
-
|
54
|
+
const result = `0x${address.join('')}` as const
|
55
|
+
checksumAddressCache.set(`${address_}.${chainId}`, result)
|
56
|
+
return result
|
39
57
|
}
|
40
58
|
|
41
59
|
export type GetAddressErrorType =
|
@@ -43,7 +61,20 @@ export type GetAddressErrorType =
|
|
43
61
|
| IsAddressErrorType
|
44
62
|
| ErrorType
|
45
63
|
|
46
|
-
export function getAddress(
|
64
|
+
export function getAddress(
|
65
|
+
address: string,
|
66
|
+
/**
|
67
|
+
* Warning: EIP-1191 checksum addresses are generally not backwards compatible with the
|
68
|
+
* wider Ethereum ecosystem, meaning it will break when validated against an application/tool
|
69
|
+
* that relies on EIP-55 checksum encoding (checksum without chainId).
|
70
|
+
*
|
71
|
+
* It is highly recommended to not use this feature unless you
|
72
|
+
* know what you are doing.
|
73
|
+
*
|
74
|
+
* See more: https://github.com/ethereum/EIPs/issues/1121
|
75
|
+
*/
|
76
|
+
chainId?: number,
|
77
|
+
): Address {
|
47
78
|
if (!isAddress(address, { strict: false }))
|
48
79
|
throw new InvalidAddressError({ address })
|
49
80
|
return checksumAddress(address, chainId)
|