Skip to content

Commit 4a79129

Browse files
committed
fix(tempo): TokenId.compute return value
1 parent d492336 commit 4a79129

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

.changeset/many-coats-protect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"ox": patch
3+
---
4+
5+
Fixed `TokenId.compute` return value.

src/tempo/TokenId.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Hex } from 'ox'
12
import { TokenId } from 'ox/tempo'
23
import { expect, test } from 'vitest'
34

@@ -46,15 +47,20 @@ test('compute', () => {
4647
const salt2 =
4748
'0x0000000000000000000000000000000000000000000000000000000000000002'
4849

49-
const address1 = TokenId.compute({ sender, salt: salt1 })
50-
const address2 = TokenId.compute({ sender, salt: salt2 })
50+
const id1 = TokenId.compute({ sender, salt: salt1 })
51+
const id2 = TokenId.compute({ sender, salt: salt2 })
52+
const address1 = TokenId.toAddress(id1)
53+
const address2 = TokenId.toAddress(id2)
5154

5255
// deterministic: same inputs produce same output
53-
expect(TokenId.compute({ sender, salt: salt1 })).toBe(address1)
56+
expect(TokenId.compute({ sender, salt: salt1 })).toBe(id1)
5457

5558
// different salts produce different addresses
5659
expect(address1).not.toBe(address2)
5760

61+
// address suffix matches id
62+
expect(Hex.slice(address1, 12)).toBe(Hex.fromNumber(id1, { size: 8 }))
63+
5864
// addresses have TIP-20 prefix (0x20c0 followed by zeroes for 12 bytes total)
5965
expect(address1.toLowerCase().startsWith('0x20c000000000000000000000')).toBe(
6066
true,

src/tempo/TokenId.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,23 @@ export function toAddress(tokenId: TokenIdOrAddress): Address.Address {
9292
* ```ts twoslash
9393
* import { TokenId } from 'ox/tempo'
9494
*
95-
* const address = TokenId.compute({
95+
* const id = TokenId.compute({
9696
* sender: '0x1234567890123456789012345678901234567890',
9797
* salt: '0x0000000000000000000000000000000000000000000000000000000000000001',
9898
* })
9999
* ```
100100
*
101101
* @param value - The sender address and salt.
102-
* @returns The computed TIP-20 token address.
102+
* @returns The computed TIP-20 token id.
103103
*/
104-
export function compute(value: compute.Value): Address.Address {
104+
export function compute(value: compute.Value): bigint {
105105
const hash = Hash.keccak256(
106106
AbiParameters.encode(AbiParameters.from('address, bytes32'), [
107107
value.sender,
108108
value.salt,
109109
]),
110110
)
111-
return Hex.concat(
112-
Hex.padRight(tip20Prefix, 12),
113-
Hex.slice(hash, 0, 8),
114-
) as Address.Address
111+
return Hex.toBigInt(Hex.slice(hash, 0, 8))
115112
}
116113

117114
export declare namespace compute {

0 commit comments

Comments
 (0)