ox 0.11.1 → 0.11.2
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/CHANGELOG.md +6 -0
- package/_cjs/tempo/TokenId.js +10 -0
- package/_cjs/tempo/TokenId.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/tempo/TokenId.js +29 -0
- package/_esm/tempo/TokenId.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/tempo/TokenId.d.ts +30 -0
- package/_types/tempo/TokenId.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/package.json +1 -1
- package/tempo/TokenId.test.ts +33 -0
- package/tempo/TokenId.ts +44 -0
- package/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# ox
|
|
2
2
|
|
|
3
|
+
## 0.11.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#153](https://github.com/wevm/ox/pull/153) [`95ebfcf`](https://github.com/wevm/ox/commit/95ebfcf1caf857b3658c26c26bb2d6ebbd88b904) Thanks [@jxom](https://github.com/jxom)! - Added `TokenId.compute` to compute deterministic TIP-20 token addresses from sender and salt.
|
|
8
|
+
|
|
3
9
|
## 0.11.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/_cjs/tempo/TokenId.js
CHANGED
|
@@ -3,7 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.from = from;
|
|
4
4
|
exports.fromAddress = fromAddress;
|
|
5
5
|
exports.toAddress = toAddress;
|
|
6
|
+
exports.compute = compute;
|
|
7
|
+
const AbiParameters = require("../core/AbiParameters.js");
|
|
6
8
|
const Address = require("../core/Address.js");
|
|
9
|
+
const Hash = require("../core/Hash.js");
|
|
7
10
|
const Hex = require("../core/Hex.js");
|
|
8
11
|
const tip20Prefix = '0x20c0';
|
|
9
12
|
function from(tokenIdOrAddress) {
|
|
@@ -25,4 +28,11 @@ function toAddress(tokenId) {
|
|
|
25
28
|
const tokenIdHex = Hex.fromNumber(tokenId, { size: 18 });
|
|
26
29
|
return Hex.concat(tip20Prefix, tokenIdHex);
|
|
27
30
|
}
|
|
31
|
+
function compute(value) {
|
|
32
|
+
const hash = Hash.keccak256(AbiParameters.encode(AbiParameters.from('address, bytes32'), [
|
|
33
|
+
value.sender,
|
|
34
|
+
value.salt,
|
|
35
|
+
]));
|
|
36
|
+
return Hex.concat(Hex.padRight(tip20Prefix, 12), Hex.slice(hash, 0, 8));
|
|
37
|
+
}
|
|
28
38
|
//# sourceMappingURL=TokenId.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenId.js","sourceRoot":"","sources":["../../tempo/TokenId.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"TokenId.js","sourceRoot":"","sources":["../../tempo/TokenId.ts"],"names":[],"mappings":";;AA4BA,oBAOC;AAiBD,kCAIC;AAiBD,8BAQC;AAsBD,0BAWC;AAlHD,0DAAyD;AACzD,8CAA6C;AAC7C,wCAAuC;AACvC,sCAAqC;AAErC,MAAM,WAAW,GAAG,QAAQ,CAAA;AAuB5B,SAAgB,IAAI,CAAC,gBAA2C;IAC9D,IACE,OAAO,gBAAgB,KAAK,QAAQ;QACpC,OAAO,gBAAgB,KAAK,QAAQ;QAEpC,OAAO,MAAM,CAAC,gBAAgB,CAAC,CAAA;IACjC,OAAO,WAAW,CAAC,gBAAgB,CAAC,CAAA;AACtC,CAAC;AAiBD,SAAgB,WAAW,CAAC,OAAwB;IAClD,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAA;IAC3C,OAAO,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAA;AAC7D,CAAC;AAiBD,SAAgB,SAAS,CAAC,OAAyB;IACjD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QACvB,OAAO,OAAO,CAAA;IAChB,CAAC;IAED,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAA;IACxD,OAAO,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;AAC5C,CAAC;AAsBD,SAAgB,OAAO,CAAC,KAAoB;IAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CACzB,aAAa,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE;QAC3D,KAAK,CAAC,MAAM;QACZ,KAAK,CAAC,IAAI;KACX,CAAC,CACH,CAAA;IACD,OAAO,GAAG,CAAC,MAAM,CACf,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC,EAC7B,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CACH,CAAA;AACtB,CAAC"}
|
package/_cjs/version.js
CHANGED
package/_esm/tempo/TokenId.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import * as AbiParameters from '../core/AbiParameters.js';
|
|
1
2
|
import * as Address from '../core/Address.js';
|
|
3
|
+
import * as Hash from '../core/Hash.js';
|
|
2
4
|
import * as Hex from '../core/Hex.js';
|
|
3
5
|
const tip20Prefix = '0x20c0';
|
|
4
6
|
/**
|
|
@@ -68,4 +70,31 @@ export function toAddress(tokenId) {
|
|
|
68
70
|
const tokenIdHex = Hex.fromNumber(tokenId, { size: 18 });
|
|
69
71
|
return Hex.concat(tip20Prefix, tokenIdHex);
|
|
70
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Computes a deterministic TIP-20 token address from a sender address and salt.
|
|
75
|
+
*
|
|
76
|
+
* The address is computed as: `TIP20_PREFIX (12 bytes) || keccak256(abi.encode(sender, salt))[:8]`
|
|
77
|
+
*
|
|
78
|
+
* [TIP-20 Token Standard](https://docs.tempo.xyz/protocol/tip20/overview)
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts twoslash
|
|
82
|
+
* import { TokenId } from 'ox/tempo'
|
|
83
|
+
*
|
|
84
|
+
* const address = TokenId.compute({
|
|
85
|
+
* sender: '0x1234567890123456789012345678901234567890',
|
|
86
|
+
* salt: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
87
|
+
* })
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @param value - The sender address and salt.
|
|
91
|
+
* @returns The computed TIP-20 token address.
|
|
92
|
+
*/
|
|
93
|
+
export function compute(value) {
|
|
94
|
+
const hash = Hash.keccak256(AbiParameters.encode(AbiParameters.from('address, bytes32'), [
|
|
95
|
+
value.sender,
|
|
96
|
+
value.salt,
|
|
97
|
+
]));
|
|
98
|
+
return Hex.concat(Hex.padRight(tip20Prefix, 12), Hex.slice(hash, 0, 8));
|
|
99
|
+
}
|
|
71
100
|
//# sourceMappingURL=TokenId.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenId.js","sourceRoot":"","sources":["../../tempo/TokenId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAC7C,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAA;AAErC,MAAM,WAAW,GAAG,QAAQ,CAAA;AAK5B;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,IAAI,CAAC,gBAA2C;IAC9D,IACE,OAAO,gBAAgB,KAAK,QAAQ;QACpC,OAAO,gBAAgB,KAAK,QAAQ;QAEpC,OAAO,MAAM,CAAC,gBAAgB,CAAC,CAAA;IACjC,OAAO,WAAW,CAAC,gBAAgB,CAAC,CAAA;AACtC,CAAC;AAED;;;;;;;;;;;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= bigint;
|
|
3
4
|
export type TokenIdOrAddress = TokenId | Address.Address;
|
|
4
5
|
/**
|
|
@@ -52,4 +53,33 @@ export declare function fromAddress(address: Address.Address): TokenId;
|
|
|
52
53
|
* @returns The address.
|
|
53
54
|
*/
|
|
54
55
|
export declare function toAddress(tokenId: TokenIdOrAddress): Address.Address;
|
|
56
|
+
/**
|
|
57
|
+
* Computes a deterministic TIP-20 token address from a sender address and salt.
|
|
58
|
+
*
|
|
59
|
+
* The address is computed as: `TIP20_PREFIX (12 bytes) || keccak256(abi.encode(sender, salt))[:8]`
|
|
60
|
+
*
|
|
61
|
+
* [TIP-20 Token Standard](https://docs.tempo.xyz/protocol/tip20/overview)
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts twoslash
|
|
65
|
+
* import { TokenId } from 'ox/tempo'
|
|
66
|
+
*
|
|
67
|
+
* const address = TokenId.compute({
|
|
68
|
+
* sender: '0x1234567890123456789012345678901234567890',
|
|
69
|
+
* salt: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
70
|
+
* })
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @param value - The sender address and salt.
|
|
74
|
+
* @returns The computed TIP-20 token address.
|
|
75
|
+
*/
|
|
76
|
+
export declare function compute(value: compute.Value): Address.Address;
|
|
77
|
+
export declare namespace compute {
|
|
78
|
+
type Value = {
|
|
79
|
+
/** The salt (32 bytes). */
|
|
80
|
+
salt: Hex.Hex;
|
|
81
|
+
/** The sender address. */
|
|
82
|
+
sender: Address.Address;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
55
85
|
//# sourceMappingURL=TokenId.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenId.d.ts","sourceRoot":"","sources":["../../tempo/TokenId.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TokenId.d.ts","sourceRoot":"","sources":["../../tempo/TokenId.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAE7C,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAA;AAIrC,MAAM,MAAM,OAAO,GAAG,MAAM,CAAA;AAC5B,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;AAExD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,IAAI,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,MAAM,GAAG,OAAO,CAOzE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,GAAG,OAAO,CAI7D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAQpE;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,OAAO,CAW7D;AAED,MAAM,CAAC,OAAO,WAAW,OAAO,CAAC;IAC/B,KAAY,KAAK,GAAG;QAClB,2BAA2B;QAC3B,IAAI,EAAE,GAAG,CAAC,GAAG,CAAA;QACb,0BAA0B;QAC1B,MAAM,EAAE,OAAO,CAAC,OAAO,CAAA;KACxB,CAAA;CACF"}
|
package/_types/version.d.ts
CHANGED
package/package.json
CHANGED
package/tempo/TokenId.test.ts
CHANGED
|
@@ -38,3 +38,36 @@ test('toAddress', () => {
|
|
|
38
38
|
'0x20c0000000000000000000000000000000000def',
|
|
39
39
|
)
|
|
40
40
|
})
|
|
41
|
+
|
|
42
|
+
test('compute', () => {
|
|
43
|
+
const sender = '0x1234567890123456789012345678901234567890'
|
|
44
|
+
const salt1 =
|
|
45
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001'
|
|
46
|
+
const salt2 =
|
|
47
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002'
|
|
48
|
+
|
|
49
|
+
const address1 = TokenId.compute({ sender, salt: salt1 })
|
|
50
|
+
const address2 = TokenId.compute({ sender, salt: salt2 })
|
|
51
|
+
|
|
52
|
+
// deterministic: same inputs produce same output
|
|
53
|
+
expect(TokenId.compute({ sender, salt: salt1 })).toBe(address1)
|
|
54
|
+
|
|
55
|
+
// different salts produce different addresses
|
|
56
|
+
expect(address1).not.toBe(address2)
|
|
57
|
+
|
|
58
|
+
// addresses have TIP-20 prefix (0x20c0 followed by zeroes for 12 bytes total)
|
|
59
|
+
expect(address1.toLowerCase().startsWith('0x20c000000000000000000000')).toBe(
|
|
60
|
+
true,
|
|
61
|
+
)
|
|
62
|
+
expect(address2.toLowerCase().startsWith('0x20c000000000000000000000')).toBe(
|
|
63
|
+
true,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
// addresses are 20 bytes (40 hex chars + 0x prefix)
|
|
67
|
+
expect(address1.length).toBe(42)
|
|
68
|
+
|
|
69
|
+
// different senders produce different addresses
|
|
70
|
+
const otherSender = '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd'
|
|
71
|
+
const address3 = TokenId.compute({ sender: otherSender, salt: salt1 })
|
|
72
|
+
expect(address3).not.toBe(address1)
|
|
73
|
+
})
|
package/tempo/TokenId.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import * as AbiParameters from '../core/AbiParameters.js'
|
|
1
2
|
import * as Address from '../core/Address.js'
|
|
3
|
+
import * as Hash from '../core/Hash.js'
|
|
2
4
|
import * as Hex from '../core/Hex.js'
|
|
3
5
|
|
|
4
6
|
const tip20Prefix = '0x20c0'
|
|
@@ -78,3 +80,45 @@ export function toAddress(tokenId: TokenIdOrAddress): Address.Address {
|
|
|
78
80
|
const tokenIdHex = Hex.fromNumber(tokenId, { size: 18 })
|
|
79
81
|
return Hex.concat(tip20Prefix, tokenIdHex)
|
|
80
82
|
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Computes a deterministic TIP-20 token address from a sender address and salt.
|
|
86
|
+
*
|
|
87
|
+
* The address is computed as: `TIP20_PREFIX (12 bytes) || keccak256(abi.encode(sender, salt))[:8]`
|
|
88
|
+
*
|
|
89
|
+
* [TIP-20 Token Standard](https://docs.tempo.xyz/protocol/tip20/overview)
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts twoslash
|
|
93
|
+
* import { TokenId } from 'ox/tempo'
|
|
94
|
+
*
|
|
95
|
+
* const address = TokenId.compute({
|
|
96
|
+
* sender: '0x1234567890123456789012345678901234567890',
|
|
97
|
+
* salt: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
98
|
+
* })
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @param value - The sender address and salt.
|
|
102
|
+
* @returns The computed TIP-20 token address.
|
|
103
|
+
*/
|
|
104
|
+
export function compute(value: compute.Value): Address.Address {
|
|
105
|
+
const hash = Hash.keccak256(
|
|
106
|
+
AbiParameters.encode(AbiParameters.from('address, bytes32'), [
|
|
107
|
+
value.sender,
|
|
108
|
+
value.salt,
|
|
109
|
+
]),
|
|
110
|
+
)
|
|
111
|
+
return Hex.concat(
|
|
112
|
+
Hex.padRight(tip20Prefix, 12),
|
|
113
|
+
Hex.slice(hash, 0, 8),
|
|
114
|
+
) as Address.Address
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export declare namespace compute {
|
|
118
|
+
export type Value = {
|
|
119
|
+
/** The salt (32 bytes). */
|
|
120
|
+
salt: Hex.Hex
|
|
121
|
+
/** The sender address. */
|
|
122
|
+
sender: Address.Address
|
|
123
|
+
}
|
|
124
|
+
}
|
package/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @internal */
|
|
2
|
-
export const version = '0.11.
|
|
2
|
+
export const version = '0.11.2'
|