ox 0.13.2 → 0.14.1
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/Bech32m/package.json +6 -0
- package/CHANGELOG.md +25 -0
- package/_cjs/core/Bech32m.js +205 -0
- package/_cjs/core/Bech32m.js.map +1 -0
- package/_cjs/index.js +3 -2
- package/_cjs/index.js.map +1 -1
- package/_cjs/tempo/AuthorizationTempo.js +7 -2
- package/_cjs/tempo/AuthorizationTempo.js.map +1 -1
- package/_cjs/tempo/KeyAuthorization.js +22 -8
- package/_cjs/tempo/KeyAuthorization.js.map +1 -1
- package/_cjs/tempo/SignatureEnvelope.js +39 -4
- package/_cjs/tempo/SignatureEnvelope.js.map +1 -1
- package/_cjs/tempo/TempoAddress.js +49 -41
- package/_cjs/tempo/TempoAddress.js.map +1 -1
- package/_cjs/tempo/TokenId.js +8 -5
- package/_cjs/tempo/TokenId.js.map +1 -1
- package/_cjs/tempo/TransactionRequest.js +2 -1
- package/_cjs/tempo/TransactionRequest.js.map +1 -1
- package/_cjs/tempo/TxEnvelopeTempo.js +17 -4
- package/_cjs/tempo/TxEnvelopeTempo.js.map +1 -1
- package/_cjs/tempo/index.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/core/Bech32m.js +238 -0
- package/_esm/core/Bech32m.js.map +1 -0
- package/_esm/index.js +24 -0
- package/_esm/index.js.map +1 -1
- package/_esm/tempo/AuthorizationTempo.js +24 -19
- package/_esm/tempo/AuthorizationTempo.js.map +1 -1
- package/_esm/tempo/KeyAuthorization.js +38 -13
- package/_esm/tempo/KeyAuthorization.js.map +1 -1
- package/_esm/tempo/SignatureEnvelope.js +43 -6
- package/_esm/tempo/SignatureEnvelope.js.map +1 -1
- package/_esm/tempo/TempoAddress.js +79 -48
- package/_esm/tempo/TempoAddress.js.map +1 -1
- package/_esm/tempo/TokenId.js +9 -6
- package/_esm/tempo/TokenId.js.map +1 -1
- package/_esm/tempo/TransactionRequest.js +2 -1
- package/_esm/tempo/TransactionRequest.js.map +1 -1
- package/_esm/tempo/TxEnvelopeTempo.js +66 -15
- package/_esm/tempo/TxEnvelopeTempo.js.map +1 -1
- package/_esm/tempo/index.js +11 -10
- package/_esm/tempo/index.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/core/Bech32m.d.ts +93 -0
- package/_types/core/Bech32m.d.ts.map +1 -0
- package/_types/index.d.ts +24 -0
- package/_types/index.d.ts.map +1 -1
- package/_types/tempo/AuthorizationTempo.d.ts +19 -19
- package/_types/tempo/AuthorizationTempo.d.ts.map +1 -1
- package/_types/tempo/KeyAuthorization.d.ts +21 -9
- package/_types/tempo/KeyAuthorization.d.ts.map +1 -1
- package/_types/tempo/SignatureEnvelope.d.ts +30 -7
- package/_types/tempo/SignatureEnvelope.d.ts.map +1 -1
- package/_types/tempo/TempoAddress.d.ts +51 -15
- package/_types/tempo/TempoAddress.d.ts.map +1 -1
- package/_types/tempo/TokenId.d.ts +6 -5
- package/_types/tempo/TokenId.d.ts.map +1 -1
- package/_types/tempo/TransactionRequest.d.ts +2 -1
- package/_types/tempo/TransactionRequest.d.ts.map +1 -1
- package/_types/tempo/TxEnvelopeTempo.d.ts +64 -17
- package/_types/tempo/TxEnvelopeTempo.d.ts.map +1 -1
- package/_types/tempo/index.d.ts +11 -10
- package/_types/tempo/index.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/core/Bech32m.ts +263 -0
- package/index.ts +24 -2
- package/package.json +6 -1
- package/tempo/AuthorizationTempo.test.ts +13 -0
- package/tempo/AuthorizationTempo.ts +27 -21
- package/tempo/KeyAuthorization.test.ts +95 -23
- package/tempo/KeyAuthorization.ts +44 -25
- package/tempo/PoolId.test.ts +9 -0
- package/tempo/SignatureEnvelope.test.ts +123 -8
- package/tempo/SignatureEnvelope.ts +82 -9
- package/tempo/TempoAddress.test.ts +70 -14
- package/tempo/TempoAddress.ts +95 -67
- package/tempo/TokenId.test.ts +14 -0
- package/tempo/TokenId.ts +13 -10
- package/tempo/Transaction.test.ts +4 -2
- package/tempo/TransactionRequest.ts +3 -2
- package/tempo/TxEnvelopeTempo.test.ts +79 -3
- package/tempo/TxEnvelopeTempo.ts +86 -19
- package/tempo/e2e.test.ts +33 -9
- package/tempo/index.ts +15 -10
- package/version.ts +1 -1
|
@@ -257,6 +257,7 @@ describe('deserialize', () => {
|
|
|
257
257
|
const keyAuthorization = KeyAuthorization.from({
|
|
258
258
|
expiry: 1234567890,
|
|
259
259
|
address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
|
|
260
|
+
chainId: 1n,
|
|
260
261
|
type: 'secp256k1',
|
|
261
262
|
limits: [
|
|
262
263
|
{
|
|
@@ -691,6 +692,32 @@ describe('from', () => {
|
|
|
691
692
|
}
|
|
692
693
|
})
|
|
693
694
|
|
|
695
|
+
test('tempo address input for calls.to', () => {
|
|
696
|
+
const hexAddr = '0x70997970c51812dc3a010c7d01b50e0d17dc79c8'
|
|
697
|
+
const tempoAddr = 'tempo1qpcfj7tsc5vp9hp6qyx86qd4pcx30hreeqlrsqqr'
|
|
698
|
+
|
|
699
|
+
const envelope = TxEnvelopeTempo.from({
|
|
700
|
+
chainId: 1,
|
|
701
|
+
calls: [{ to: tempoAddr }],
|
|
702
|
+
nonce: 0n,
|
|
703
|
+
nonceKey: 0n,
|
|
704
|
+
})
|
|
705
|
+
expect(envelope.calls[0]!.to).toBe(Address.checksum(hexAddr))
|
|
706
|
+
})
|
|
707
|
+
|
|
708
|
+
test('tempo address input for from', () => {
|
|
709
|
+
const hexAddr = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
|
|
710
|
+
const tempoAddr = 'tempo1qreel4h9r2kc3ah5ee4t3qnj088llwfzvccugvl7'
|
|
711
|
+
|
|
712
|
+
const envelope = TxEnvelopeTempo.from({
|
|
713
|
+
chainId: 1,
|
|
714
|
+
calls: [{}],
|
|
715
|
+
nonce: 0n,
|
|
716
|
+
from: tempoAddr as any,
|
|
717
|
+
})
|
|
718
|
+
expect(envelope.from).toBe(Address.checksum(hexAddr))
|
|
719
|
+
})
|
|
720
|
+
|
|
694
721
|
test('options: signature', () => {
|
|
695
722
|
const envelope = TxEnvelopeTempo.from(
|
|
696
723
|
{
|
|
@@ -894,6 +921,7 @@ describe('serialize', () => {
|
|
|
894
921
|
test('keyAuthorization (secp256k1)', () => {
|
|
895
922
|
const keyAuthorization = KeyAuthorization.from({
|
|
896
923
|
address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
|
|
924
|
+
chainId: 1n,
|
|
897
925
|
expiry: 1234567890,
|
|
898
926
|
type: 'secp256k1',
|
|
899
927
|
limits: [
|
|
@@ -918,7 +946,7 @@ describe('serialize', () => {
|
|
|
918
946
|
|
|
919
947
|
const serialized = TxEnvelopeTempo.serialize(transaction)
|
|
920
948
|
expect(serialized).toMatchInlineSnapshot(
|
|
921
|
-
`"
|
|
949
|
+
`"0x76f8a201808080d8d79470997970c51812dc3a010c7d01b50e0d17dc79c88080c0808080808080c0f87bf7018094be95c3f554e9fc85ec51be69a3d807a0d55bcf2c84499602d2dad99420c000000000000000000000000000000000000183989680b841635dc2033e60185bb36709c29c75d64ea51dfbd91c32ef4be198e4ceb169fb4d50c2667ac4c771072746acfdcf1f1483336dcca8bd2df47cd83175dbe60f05401b"`,
|
|
922
950
|
)
|
|
923
951
|
|
|
924
952
|
const deserialized = TxEnvelopeTempo.deserialize(serialized)
|
|
@@ -928,6 +956,7 @@ describe('serialize', () => {
|
|
|
928
956
|
test('keyAuthorization (p256)', () => {
|
|
929
957
|
const keyAuthorization = KeyAuthorization.from({
|
|
930
958
|
address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
|
|
959
|
+
chainId: 1n,
|
|
931
960
|
expiry: 1234567890,
|
|
932
961
|
type: 'p256',
|
|
933
962
|
limits: [
|
|
@@ -959,7 +988,7 @@ describe('serialize', () => {
|
|
|
959
988
|
|
|
960
989
|
const serialized = TxEnvelopeTempo.serialize(transaction)
|
|
961
990
|
expect(serialized).toMatchInlineSnapshot(
|
|
962
|
-
`"
|
|
991
|
+
`"0x76f8e301808080d8d79470997970c51812dc3a010c7d01b50e0d17dc79c88080c0808080808080c0f8bcf7010194be95c3f554e9fc85ec51be69a3d807a0d55bcf2c84499602d2dad99420c000000000000000000000000000000000000183989680b88201ccbb3485d4726235f13cb15ef394fb7158179fb7b1925eccec0147671090c52e77c3c53373cc1e3b05e7c23f609deb17cea8fe097300c45411237e9fe4166b35ad8ac16e167d6992c3e120d7f17d2376bc1cbcf30c46ba6dd00ce07303e742f511edf6ce1c32de66846f56afa7be1cbd729bc35750b6d0cdcf3ec9d75461aba001"`,
|
|
963
992
|
)
|
|
964
993
|
|
|
965
994
|
const deserialized = TxEnvelopeTempo.deserialize(serialized)
|
|
@@ -979,6 +1008,7 @@ describe('serialize', () => {
|
|
|
979
1008
|
|
|
980
1009
|
const keyAuthorization = KeyAuthorization.from({
|
|
981
1010
|
address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
|
|
1011
|
+
chainId: 1n,
|
|
982
1012
|
expiry: 1234567890,
|
|
983
1013
|
type: 'webAuthn',
|
|
984
1014
|
limits: [
|
|
@@ -1010,7 +1040,7 @@ describe('serialize', () => {
|
|
|
1010
1040
|
|
|
1011
1041
|
const serialized = TxEnvelopeTempo.serialize(transaction)
|
|
1012
1042
|
expect(serialized).toMatchInlineSnapshot(
|
|
1013
|
-
`"
|
|
1043
|
+
`"0x76f9016501808080d8d79470997970c51812dc3a010c7d01b50e0d17dc79c88080c0808080808080c0f9013df7010294be95c3f554e9fc85ec51be69a3d807a0d55bcf2c84499602d2dad99420c000000000000000000000000000000000000183989680b901020249960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d976305000000007b2274797065223a22776562617574686e2e676574222c226368616c6c656e6765223a223371322d3777222c226f726967696e223a22687474703a2f2f6c6f63616c686f7374222c2263726f73734f726967696e223a66616c73657dccbb3485d4726235f13cb15ef394fb7158179fb7b1925eccec0147671090c52e77c3c53373cc1e3b05e7c23f609deb17cea8fe097300c45411237e9fe4166b35ad8ac16e167d6992c3e120d7f17d2376bc1cbcf30c46ba6dd00ce07303e742f511edf6ce1c32de66846f56afa7be1cbd729bc35750b6d0cdcf3ec9d75461aba0"`,
|
|
1014
1044
|
)
|
|
1015
1045
|
|
|
1016
1046
|
// Verify roundtrip
|
|
@@ -1378,6 +1408,29 @@ describe('getSignPayload', () => {
|
|
|
1378
1408
|
`"0xe1222a45806457acbe3a13940aae4c34f3180659fa16613b5a45dc183adae07c"`,
|
|
1379
1409
|
)
|
|
1380
1410
|
})
|
|
1411
|
+
|
|
1412
|
+
test('tempo address input for from', () => {
|
|
1413
|
+
const hexAddr = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
|
|
1414
|
+
const tempoAddr = 'tempo1qreel4h9r2kc3ah5ee4t3qnj088llwfzvccugvl7'
|
|
1415
|
+
|
|
1416
|
+
const transaction = TxEnvelopeTempo.from({
|
|
1417
|
+
chainId: 1,
|
|
1418
|
+
calls: [
|
|
1419
|
+
{
|
|
1420
|
+
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
|
1421
|
+
},
|
|
1422
|
+
],
|
|
1423
|
+
nonce: 0n,
|
|
1424
|
+
})
|
|
1425
|
+
|
|
1426
|
+
const hashHex = TxEnvelopeTempo.getSignPayload(transaction, {
|
|
1427
|
+
from: hexAddr,
|
|
1428
|
+
})
|
|
1429
|
+
const hashTempo = TxEnvelopeTempo.getSignPayload(transaction, {
|
|
1430
|
+
from: tempoAddr,
|
|
1431
|
+
})
|
|
1432
|
+
expect(hashTempo).toBe(hashHex)
|
|
1433
|
+
})
|
|
1381
1434
|
})
|
|
1382
1435
|
|
|
1383
1436
|
describe('getFeePayerSignPayload', () => {
|
|
@@ -1400,6 +1453,29 @@ describe('getFeePayerSignPayload', () => {
|
|
|
1400
1453
|
)
|
|
1401
1454
|
})
|
|
1402
1455
|
|
|
1456
|
+
test('tempo address input for sender', () => {
|
|
1457
|
+
const hexAddr = '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'
|
|
1458
|
+
const tempoAddr = 'tempo1qreel4h9r2kc3ah5ee4t3qnj088llwfzvccugvl7'
|
|
1459
|
+
|
|
1460
|
+
const transaction = TxEnvelopeTempo.from({
|
|
1461
|
+
chainId: 1,
|
|
1462
|
+
calls: [
|
|
1463
|
+
{
|
|
1464
|
+
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
|
1465
|
+
},
|
|
1466
|
+
],
|
|
1467
|
+
nonce: 0n,
|
|
1468
|
+
})
|
|
1469
|
+
|
|
1470
|
+
const hashHex = TxEnvelopeTempo.getFeePayerSignPayload(transaction, {
|
|
1471
|
+
sender: hexAddr,
|
|
1472
|
+
})
|
|
1473
|
+
const hashTempo = TxEnvelopeTempo.getFeePayerSignPayload(transaction, {
|
|
1474
|
+
sender: tempoAddr,
|
|
1475
|
+
})
|
|
1476
|
+
expect(hashTempo).toBe(hashHex)
|
|
1477
|
+
})
|
|
1478
|
+
|
|
1403
1479
|
test('with feeToken', () => {
|
|
1404
1480
|
const transaction = TxEnvelopeTempo.from({
|
|
1405
1481
|
chainId: 1,
|
package/tempo/TxEnvelopeTempo.ts
CHANGED
|
@@ -17,6 +17,7 @@ import * as TransactionEnvelope from '../core/TxEnvelope.js'
|
|
|
17
17
|
import * as AuthorizationTempo from './AuthorizationTempo.js'
|
|
18
18
|
import * as KeyAuthorization from './KeyAuthorization.js'
|
|
19
19
|
import * as SignatureEnvelope from './SignatureEnvelope.js'
|
|
20
|
+
import * as TempoAddress from './TempoAddress.js'
|
|
20
21
|
import * as TokenId from './TokenId.js'
|
|
21
22
|
|
|
22
23
|
/**
|
|
@@ -26,11 +27,11 @@ import * as TokenId from './TokenId.js'
|
|
|
26
27
|
*
|
|
27
28
|
* [Batch Calls](https://docs.tempo.xyz/protocol/transactions#batch-calls)
|
|
28
29
|
*/
|
|
29
|
-
export type Call<bigintType = bigint> = {
|
|
30
|
+
export type Call<bigintType = bigint, addressType = Address.Address> = {
|
|
30
31
|
/** Call data. */
|
|
31
32
|
data?: Hex.Hex | undefined
|
|
32
33
|
/** The target address or contract creation. */
|
|
33
|
-
to?:
|
|
34
|
+
to?: addressType | undefined
|
|
34
35
|
/** Value to send (in wei). */
|
|
35
36
|
value?: bigintType | undefined
|
|
36
37
|
}
|
|
@@ -77,11 +78,11 @@ export type TxEnvelopeTempo<
|
|
|
77
78
|
| AuthorizationTempo.ListSigned<bigintType, numberType>
|
|
78
79
|
| undefined
|
|
79
80
|
/** Array of calls to execute. */
|
|
80
|
-
calls: readonly Call<bigintType>[]
|
|
81
|
+
calls: readonly Call<bigintType, TempoAddress.Address>[]
|
|
81
82
|
/** EIP-155 Chain ID. */
|
|
82
83
|
chainId: numberType
|
|
83
84
|
/** Sender of the transaction. */
|
|
84
|
-
from?:
|
|
85
|
+
from?: TempoAddress.Address | undefined
|
|
85
86
|
/** Gas provided for transaction execution */
|
|
86
87
|
gas?: bigintType | undefined
|
|
87
88
|
/** Fee payer signature. */
|
|
@@ -154,7 +155,7 @@ export type Type = typeof type
|
|
|
154
155
|
* import { TxEnvelopeTempo } from 'ox/tempo'
|
|
155
156
|
*
|
|
156
157
|
* TxEnvelopeTempo.assert({
|
|
157
|
-
* calls: [{ to: '
|
|
158
|
+
* calls: [{ to: 'tempo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj97hme', value: 0n }],
|
|
158
159
|
* chainId: 1,
|
|
159
160
|
* maxFeePerGas: 1000000000n,
|
|
160
161
|
* })
|
|
@@ -413,7 +414,7 @@ export declare namespace deserialize {
|
|
|
413
414
|
* chainId: 1, // [!code focus]
|
|
414
415
|
* calls: [{ // [!code focus]
|
|
415
416
|
* data: '0xdeadbeef', // [!code focus]
|
|
416
|
-
* to: '
|
|
417
|
+
* to: 'tempo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj97hme', // [!code focus]
|
|
417
418
|
* }], // [!code focus]
|
|
418
419
|
* maxFeePerGas: Value.fromGwei('10'), // [!code focus]
|
|
419
420
|
* maxPriorityFeePerGas: Value.fromGwei('1'), // [!code focus]
|
|
@@ -434,7 +435,7 @@ export declare namespace deserialize {
|
|
|
434
435
|
* chainId: 1,
|
|
435
436
|
* calls: [{
|
|
436
437
|
* data: '0xdeadbeef',
|
|
437
|
-
* to: '
|
|
438
|
+
* to: 'tempo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj97hme',
|
|
438
439
|
* }],
|
|
439
440
|
* maxFeePerGas: Value.fromGwei('10'),
|
|
440
441
|
* maxPriorityFeePerGas: Value.fromGwei('1'),
|
|
@@ -497,6 +498,19 @@ export function from<
|
|
|
497
498
|
typeof envelope === 'string' ? deserialize(envelope) : envelope
|
|
498
499
|
) as TxEnvelopeTempo
|
|
499
500
|
|
|
501
|
+
// Resolve TempoAddress inputs to hex addresses.
|
|
502
|
+
if (envelope_.from)
|
|
503
|
+
envelope_.from = TempoAddress.resolve(
|
|
504
|
+
envelope_.from as TempoAddress.Address,
|
|
505
|
+
)
|
|
506
|
+
if (envelope_.calls)
|
|
507
|
+
envelope_.calls = (envelope_.calls as readonly Call[]).map((call) => ({
|
|
508
|
+
...call,
|
|
509
|
+
...(call.to
|
|
510
|
+
? { to: TempoAddress.resolve(call.to as TempoAddress.Address) }
|
|
511
|
+
: {}),
|
|
512
|
+
})) as readonly Call[]
|
|
513
|
+
|
|
500
514
|
assert(envelope_)
|
|
501
515
|
|
|
502
516
|
return {
|
|
@@ -559,7 +573,7 @@ export declare namespace from {
|
|
|
559
573
|
* chainId: 1,
|
|
560
574
|
* calls: [{
|
|
561
575
|
* data: '0xdeadbeef',
|
|
562
|
-
* to: '
|
|
576
|
+
* to: 'tempo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj97hme',
|
|
563
577
|
* }],
|
|
564
578
|
* maxFeePerGas: Value.fromGwei('10'),
|
|
565
579
|
* })
|
|
@@ -581,7 +595,7 @@ export declare namespace from {
|
|
|
581
595
|
* chainId: 1,
|
|
582
596
|
* calls: [{
|
|
583
597
|
* data: '0xdeadbeef',
|
|
584
|
-
* to: '
|
|
598
|
+
* to: 'tempo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj97hme',
|
|
585
599
|
* }],
|
|
586
600
|
* maxFeePerGas: Value.fromGwei('10'),
|
|
587
601
|
* })
|
|
@@ -632,7 +646,7 @@ export function serialize(
|
|
|
632
646
|
|
|
633
647
|
// Encode calls as RLP list of [to, value, data] tuples
|
|
634
648
|
const callsTupleList = calls.map((call) => [
|
|
635
|
-
call.to
|
|
649
|
+
call.to ? TempoAddress.resolve(call.to) : '0x',
|
|
636
650
|
call.value ? Hex.fromNumber(call.value) : '0x',
|
|
637
651
|
call.data ?? '0x',
|
|
638
652
|
])
|
|
@@ -766,7 +780,7 @@ export declare namespace serialize {
|
|
|
766
780
|
* chainId: 1,
|
|
767
781
|
* calls: [{
|
|
768
782
|
* data: '0xdeadbeef',
|
|
769
|
-
* to: '
|
|
783
|
+
* to: 'tempo1qpcfj7tsc5vp9hp6qyx86qd4pcx30hreeqlrsqqr',
|
|
770
784
|
* }],
|
|
771
785
|
* nonce: 0n,
|
|
772
786
|
* maxFeePerGas: 1000000000n,
|
|
@@ -779,16 +793,69 @@ export declare namespace serialize {
|
|
|
779
793
|
* const signature = Secp256k1.sign({ payload, privateKey: '0x...' })
|
|
780
794
|
* ```
|
|
781
795
|
*
|
|
796
|
+
* @example
|
|
797
|
+
* ### Access Keys
|
|
798
|
+
*
|
|
799
|
+
* When signing as an access key on behalf of a root account, pass the
|
|
800
|
+
* `from` option with the root account address. This computes
|
|
801
|
+
* `keccak256(0x04 || sigHash || from)` which binds the signature to the
|
|
802
|
+
* specific user account (V2 keychain format).
|
|
803
|
+
*
|
|
804
|
+
* ```ts twoslash
|
|
805
|
+
* // @noErrors
|
|
806
|
+
* import { Secp256k1 } from 'ox'
|
|
807
|
+
* import { TxEnvelopeTempo, SignatureEnvelope } from 'ox/tempo'
|
|
808
|
+
*
|
|
809
|
+
* const envelope = TxEnvelopeTempo.from({
|
|
810
|
+
* chainId: 1,
|
|
811
|
+
* calls: [{
|
|
812
|
+
* data: '0xdeadbeef',
|
|
813
|
+
* to: 'tempo1qpcfj7tsc5vp9hp6qyx86qd4pcx30hreeqlrsqqr',
|
|
814
|
+
* }],
|
|
815
|
+
* nonce: 0n,
|
|
816
|
+
* maxFeePerGas: 1000000000n,
|
|
817
|
+
* gas: 21000n,
|
|
818
|
+
* })
|
|
819
|
+
*
|
|
820
|
+
* const payload = TxEnvelopeTempo.getSignPayload(envelope, { from: '0x...' }) // [!code focus]
|
|
821
|
+
*
|
|
822
|
+
* const signature = Secp256k1.sign({ payload, privateKey: '0x...' })
|
|
823
|
+
*
|
|
824
|
+
* const signed = TxEnvelopeTempo.serialize(envelope, {
|
|
825
|
+
* signature: SignatureEnvelope.from({
|
|
826
|
+
* userAddress: from,
|
|
827
|
+
* inner: SignatureEnvelope.from(signature),
|
|
828
|
+
* }),
|
|
829
|
+
* })
|
|
830
|
+
* ```
|
|
831
|
+
*
|
|
782
832
|
* @param envelope - The transaction envelope to get the sign payload for.
|
|
833
|
+
* @param options - Options.
|
|
783
834
|
* @returns The sign payload.
|
|
784
835
|
*/
|
|
785
836
|
export function getSignPayload(
|
|
786
837
|
envelope: TxEnvelopeTempo,
|
|
838
|
+
options: getSignPayload.Options = {},
|
|
787
839
|
): getSignPayload.ReturnValue {
|
|
788
|
-
|
|
840
|
+
const sigHash = hash(envelope, { presign: true })
|
|
841
|
+
if (options.from)
|
|
842
|
+
return Hash.keccak256(
|
|
843
|
+
Hex.concat('0x04', sigHash, TempoAddress.resolve(options.from)),
|
|
844
|
+
)
|
|
845
|
+
return sigHash
|
|
789
846
|
}
|
|
790
847
|
|
|
791
848
|
export declare namespace getSignPayload {
|
|
849
|
+
type Options = {
|
|
850
|
+
/**
|
|
851
|
+
* The root account address for access key signing.
|
|
852
|
+
*
|
|
853
|
+
* When provided, computes `keccak256(0x04 || sigHash || from)` instead of
|
|
854
|
+
* the raw `sigHash`, binding the access key signature to the specific user account.
|
|
855
|
+
*/
|
|
856
|
+
from?: TempoAddress.Address | undefined
|
|
857
|
+
}
|
|
858
|
+
|
|
792
859
|
type ReturnValue = Hex.Hex
|
|
793
860
|
|
|
794
861
|
type ErrorType = hash.ErrorType | Errors.GlobalErrorType
|
|
@@ -807,7 +874,7 @@ export declare namespace getSignPayload {
|
|
|
807
874
|
* chainId: 1,
|
|
808
875
|
* calls: [{
|
|
809
876
|
* data: '0xdeadbeef',
|
|
810
|
-
* to: '
|
|
877
|
+
* to: 'tempo1qpcfj7tsc5vp9hp6qyx86qd4pcx30hreeqlrsqqr',
|
|
811
878
|
* }],
|
|
812
879
|
* nonce: 0n,
|
|
813
880
|
* maxFeePerGas: 1000000000n,
|
|
@@ -881,7 +948,7 @@ export declare namespace hash {
|
|
|
881
948
|
* chainId: 1,
|
|
882
949
|
* calls: [{
|
|
883
950
|
* data: '0xdeadbeef',
|
|
884
|
-
* to: '
|
|
951
|
+
* to: 'tempo1qpcfj7tsc5vp9hp6qyx86qd4pcx30hreeqlrsqqr',
|
|
885
952
|
* }],
|
|
886
953
|
* nonce: 0n,
|
|
887
954
|
* maxFeePerGas: 1000000000n,
|
|
@@ -889,7 +956,7 @@ export declare namespace hash {
|
|
|
889
956
|
* })
|
|
890
957
|
*
|
|
891
958
|
* const payload = TxEnvelopeTempo.getFeePayerSignPayload(envelope, {
|
|
892
|
-
* sender: '
|
|
959
|
+
* sender: 'tempo1qrvd56ljd9j2l8t7ak0q8ef5zhfh42tqg5kwwrau'
|
|
893
960
|
* }) // [!code focus]
|
|
894
961
|
* // @log: '0x...'
|
|
895
962
|
*
|
|
@@ -904,7 +971,7 @@ export function getFeePayerSignPayload(
|
|
|
904
971
|
envelope: TxEnvelopeTempo,
|
|
905
972
|
options: getFeePayerSignPayload.Options,
|
|
906
973
|
): getFeePayerSignPayload.ReturnValue {
|
|
907
|
-
const
|
|
974
|
+
const sender = TempoAddress.resolve(options.sender)
|
|
908
975
|
const serialized = serialize(
|
|
909
976
|
{ ...envelope, signature: undefined },
|
|
910
977
|
{
|
|
@@ -920,7 +987,7 @@ export declare namespace getFeePayerSignPayload {
|
|
|
920
987
|
/**
|
|
921
988
|
* Sender address to cover the fee of.
|
|
922
989
|
*/
|
|
923
|
-
sender:
|
|
990
|
+
sender: TempoAddress.Address
|
|
924
991
|
}
|
|
925
992
|
|
|
926
993
|
type ReturnValue = Hex.Hex
|
|
@@ -938,7 +1005,7 @@ export declare namespace getFeePayerSignPayload {
|
|
|
938
1005
|
* const valid = TxEnvelopeTempo.validate({
|
|
939
1006
|
* calls: [{
|
|
940
1007
|
* data: '0xdeadbeef',
|
|
941
|
-
* to: '
|
|
1008
|
+
* to: 'tempo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj97hme',
|
|
942
1009
|
* }],
|
|
943
1010
|
* chainId: 1,
|
|
944
1011
|
* maxFeePerGas: 1000000000n,
|
|
@@ -990,7 +1057,7 @@ export class CallsEmptyError extends Errors.BaseError {
|
|
|
990
1057
|
* import { TxEnvelopeTempo } from 'ox/tempo'
|
|
991
1058
|
*
|
|
992
1059
|
* TxEnvelopeTempo.assert({
|
|
993
|
-
* calls: [{ to: '
|
|
1060
|
+
* calls: [{ to: 'tempo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj97hme' }],
|
|
994
1061
|
* chainId: 1,
|
|
995
1062
|
* validBefore: 100,
|
|
996
1063
|
* validAfter: 200,
|
package/tempo/e2e.test.ts
CHANGED
|
@@ -806,6 +806,7 @@ describe('behavior: keyAuthorization', () => {
|
|
|
806
806
|
|
|
807
807
|
const keyAuth = KeyAuthorization.from({
|
|
808
808
|
address: access.address,
|
|
809
|
+
chainId: BigInt(chain.id),
|
|
809
810
|
type: 'secp256k1',
|
|
810
811
|
})
|
|
811
812
|
|
|
@@ -839,7 +840,9 @@ describe('behavior: keyAuthorization', () => {
|
|
|
839
840
|
})
|
|
840
841
|
|
|
841
842
|
const signature = Secp256k1.sign({
|
|
842
|
-
payload: TxEnvelopeTempo.getSignPayload(transaction
|
|
843
|
+
payload: TxEnvelopeTempo.getSignPayload(transaction, {
|
|
844
|
+
from: root.address,
|
|
845
|
+
}),
|
|
843
846
|
privateKey: access.privateKey,
|
|
844
847
|
})
|
|
845
848
|
|
|
@@ -978,7 +981,9 @@ describe('behavior: keyAuthorization', () => {
|
|
|
978
981
|
})
|
|
979
982
|
|
|
980
983
|
const signature = Secp256k1.sign({
|
|
981
|
-
payload: TxEnvelopeTempo.getSignPayload(transaction
|
|
984
|
+
payload: TxEnvelopeTempo.getSignPayload(transaction, {
|
|
985
|
+
from: root.address,
|
|
986
|
+
}),
|
|
982
987
|
privateKey: access.privateKey,
|
|
983
988
|
})
|
|
984
989
|
|
|
@@ -1012,6 +1017,7 @@ describe('behavior: keyAuthorization', () => {
|
|
|
1012
1017
|
|
|
1013
1018
|
const keyAuth = KeyAuthorization.from({
|
|
1014
1019
|
address: access.address,
|
|
1020
|
+
chainId: BigInt(chainId),
|
|
1015
1021
|
type: 'p256',
|
|
1016
1022
|
})
|
|
1017
1023
|
|
|
@@ -1045,7 +1051,9 @@ describe('behavior: keyAuthorization', () => {
|
|
|
1045
1051
|
})
|
|
1046
1052
|
|
|
1047
1053
|
const signature = P256.sign({
|
|
1048
|
-
payload: TxEnvelopeTempo.getSignPayload(transaction
|
|
1054
|
+
payload: TxEnvelopeTempo.getSignPayload(transaction, {
|
|
1055
|
+
from: root.address,
|
|
1056
|
+
}),
|
|
1049
1057
|
privateKey: access.privateKey,
|
|
1050
1058
|
})
|
|
1051
1059
|
|
|
@@ -1190,7 +1198,9 @@ describe('behavior: keyAuthorization', () => {
|
|
|
1190
1198
|
})
|
|
1191
1199
|
|
|
1192
1200
|
const signature = P256.sign({
|
|
1193
|
-
payload: TxEnvelopeTempo.getSignPayload(transaction
|
|
1201
|
+
payload: TxEnvelopeTempo.getSignPayload(transaction, {
|
|
1202
|
+
from: root.address,
|
|
1203
|
+
}),
|
|
1194
1204
|
privateKey: access.privateKey,
|
|
1195
1205
|
})
|
|
1196
1206
|
|
|
@@ -1227,6 +1237,7 @@ describe('behavior: keyAuthorization', () => {
|
|
|
1227
1237
|
|
|
1228
1238
|
const keyAuth = KeyAuthorization.from({
|
|
1229
1239
|
address: access.address,
|
|
1240
|
+
chainId: BigInt(chainId),
|
|
1230
1241
|
type: 'p256',
|
|
1231
1242
|
})
|
|
1232
1243
|
|
|
@@ -1260,7 +1271,9 @@ describe('behavior: keyAuthorization', () => {
|
|
|
1260
1271
|
})
|
|
1261
1272
|
|
|
1262
1273
|
const signature = await WebCryptoP256.sign({
|
|
1263
|
-
payload: TxEnvelopeTempo.getSignPayload(transaction
|
|
1274
|
+
payload: TxEnvelopeTempo.getSignPayload(transaction, {
|
|
1275
|
+
from: root.address,
|
|
1276
|
+
}),
|
|
1264
1277
|
privateKey: keyPair.privateKey,
|
|
1265
1278
|
})
|
|
1266
1279
|
|
|
@@ -1366,7 +1379,9 @@ describe('behavior: keyAuthorization', () => {
|
|
|
1366
1379
|
})
|
|
1367
1380
|
|
|
1368
1381
|
const signature = await WebCryptoP256.sign({
|
|
1369
|
-
payload: TxEnvelopeTempo.getSignPayload(transaction
|
|
1382
|
+
payload: TxEnvelopeTempo.getSignPayload(transaction, {
|
|
1383
|
+
from: root.address,
|
|
1384
|
+
}),
|
|
1370
1385
|
privateKey: keyPair.privateKey,
|
|
1371
1386
|
})
|
|
1372
1387
|
|
|
@@ -1404,6 +1419,7 @@ describe('behavior: keyAuthorization', () => {
|
|
|
1404
1419
|
|
|
1405
1420
|
const keyAuth = KeyAuthorization.from({
|
|
1406
1421
|
address: access.address,
|
|
1422
|
+
chainId: BigInt(chainId),
|
|
1407
1423
|
type: 'p256',
|
|
1408
1424
|
expiry: Math.floor(Date.now() / 1000) + 60 * 60,
|
|
1409
1425
|
limits: [
|
|
@@ -1444,7 +1460,9 @@ describe('behavior: keyAuthorization', () => {
|
|
|
1444
1460
|
})
|
|
1445
1461
|
|
|
1446
1462
|
const signature = P256.sign({
|
|
1447
|
-
payload: TxEnvelopeTempo.getSignPayload(transaction
|
|
1463
|
+
payload: TxEnvelopeTempo.getSignPayload(transaction, {
|
|
1464
|
+
from: root.address,
|
|
1465
|
+
}),
|
|
1448
1466
|
privateKey: access.privateKey,
|
|
1449
1467
|
})
|
|
1450
1468
|
|
|
@@ -1498,6 +1516,7 @@ describe('behavior: keyAuthorization', () => {
|
|
|
1498
1516
|
|
|
1499
1517
|
const keyAuth = KeyAuthorization.from({
|
|
1500
1518
|
address: access.address,
|
|
1519
|
+
chainId: BigInt(chainId),
|
|
1501
1520
|
type: 'secp256k1',
|
|
1502
1521
|
limits: [
|
|
1503
1522
|
{
|
|
@@ -1537,7 +1556,9 @@ describe('behavior: keyAuthorization', () => {
|
|
|
1537
1556
|
})
|
|
1538
1557
|
|
|
1539
1558
|
const signature = Secp256k1.sign({
|
|
1540
|
-
payload: TxEnvelopeTempo.getSignPayload(transaction
|
|
1559
|
+
payload: TxEnvelopeTempo.getSignPayload(transaction, {
|
|
1560
|
+
from: root.address,
|
|
1561
|
+
}),
|
|
1541
1562
|
privateKey: access.privateKey,
|
|
1542
1563
|
})
|
|
1543
1564
|
|
|
@@ -1586,6 +1607,7 @@ describe('behavior: keyAuthorization', () => {
|
|
|
1586
1607
|
|
|
1587
1608
|
const keyAuth = KeyAuthorization.from({
|
|
1588
1609
|
address: access.address,
|
|
1610
|
+
chainId: BigInt(chainId),
|
|
1589
1611
|
type: 'secp256k1',
|
|
1590
1612
|
expiry: Math.floor(Date.now() / 1000) + 60 * 60,
|
|
1591
1613
|
})
|
|
@@ -1620,7 +1642,9 @@ describe('behavior: keyAuthorization', () => {
|
|
|
1620
1642
|
})
|
|
1621
1643
|
|
|
1622
1644
|
const signature = Secp256k1.sign({
|
|
1623
|
-
payload: TxEnvelopeTempo.getSignPayload(transaction
|
|
1645
|
+
payload: TxEnvelopeTempo.getSignPayload(transaction, {
|
|
1646
|
+
from: root.address,
|
|
1647
|
+
}),
|
|
1624
1648
|
privateKey: access.privateKey,
|
|
1625
1649
|
})
|
|
1626
1650
|
|
package/tempo/index.ts
CHANGED
|
@@ -17,7 +17,7 @@ export type {}
|
|
|
17
17
|
* import { AuthorizationTempo } from 'ox/tempo'
|
|
18
18
|
*
|
|
19
19
|
* const authorization = AuthorizationTempo.from({
|
|
20
|
-
* address: '
|
|
20
|
+
* address: 'tempo1qzlftsl42n5lep0v2xlxng7cq7sd2k709sxlwnsu',
|
|
21
21
|
* chainId: 1,
|
|
22
22
|
* nonce: 40n,
|
|
23
23
|
* })
|
|
@@ -55,10 +55,11 @@ export * as AuthorizationTempo from './AuthorizationTempo.js'
|
|
|
55
55
|
*
|
|
56
56
|
* const authorization = KeyAuthorization.from({
|
|
57
57
|
* address,
|
|
58
|
+
* chainId: 4217n,
|
|
58
59
|
* expiry: 1234567890,
|
|
59
60
|
* type: 'p256',
|
|
60
61
|
* limits: [{
|
|
61
|
-
* token: '
|
|
62
|
+
* token: 'tempo1qqsvqqqqqqqqqqqqqqqqqqqqqqqqqqqqqyr9xgnd',
|
|
62
63
|
* limit: Value.from('10', 6),
|
|
63
64
|
* }],
|
|
64
65
|
* })
|
|
@@ -120,6 +121,7 @@ export * as PoolId from './PoolId.js'
|
|
|
120
121
|
* @category Reference
|
|
121
122
|
*/
|
|
122
123
|
export * as SignatureEnvelope from './SignatureEnvelope.js'
|
|
124
|
+
|
|
123
125
|
/**
|
|
124
126
|
* Tempo address encoding/decoding utilities for human-readable addresses.
|
|
125
127
|
*
|
|
@@ -132,15 +134,16 @@ export * as SignatureEnvelope from './SignatureEnvelope.js'
|
|
|
132
134
|
* import { TempoAddress } from 'ox/tempo'
|
|
133
135
|
*
|
|
134
136
|
* const encoded = TempoAddress.format('0x742d35Cc6634C0532925a3b844Bc9e7595f2bD28')
|
|
135
|
-
* // @log: '
|
|
137
|
+
* // @log: 'tempo1wskntnrxxnq9x2f95wuyf0y7wk2l90fg0hlz9j'
|
|
136
138
|
*
|
|
137
139
|
* const { address, zoneId } = TempoAddress.parse(encoded)
|
|
138
|
-
* // @log: { address: '0x742d35CC6634c0532925a3B844bc9e7595F2Bd28' }
|
|
140
|
+
* // @log: { address: '0x742d35CC6634c0532925a3B844bc9e7595F2Bd28', zoneId: undefined }
|
|
139
141
|
* ```
|
|
140
142
|
*
|
|
141
143
|
* @category Reference
|
|
142
144
|
*/
|
|
143
145
|
export * as TempoAddress from './TempoAddress.js'
|
|
146
|
+
|
|
144
147
|
/**
|
|
145
148
|
* Tick-based pricing utilities for DEX price conversions.
|
|
146
149
|
*
|
|
@@ -161,6 +164,7 @@ export * as TempoAddress from './TempoAddress.js'
|
|
|
161
164
|
* @category Reference
|
|
162
165
|
*/
|
|
163
166
|
export * as Tick from './Tick.js'
|
|
167
|
+
|
|
164
168
|
/**
|
|
165
169
|
* TIP-20 token ID utilities for converting between token IDs and addresses.
|
|
166
170
|
*
|
|
@@ -176,12 +180,13 @@ export * as Tick from './Tick.js'
|
|
|
176
180
|
*
|
|
177
181
|
* const tokenId = TokenId.from(1n)
|
|
178
182
|
* const address = TokenId.toAddress(1n)
|
|
179
|
-
* // '
|
|
183
|
+
* // 'tempo1qqsvqqqqqqqqqqqqqqqqqqqqqqqqqqqqqyr9xgnd'
|
|
180
184
|
* ```
|
|
181
185
|
*
|
|
182
186
|
* @category Reference
|
|
183
187
|
*/
|
|
184
188
|
export * as TokenId from './TokenId.js'
|
|
189
|
+
|
|
185
190
|
/**
|
|
186
191
|
* Token role utilities for serializing role identifiers to keccak256 hashes.
|
|
187
192
|
*
|
|
@@ -227,7 +232,7 @@ export * as TokenRole from './TokenRole.js'
|
|
|
227
232
|
* value: '0x9b6e64a8ec60000',
|
|
228
233
|
* },
|
|
229
234
|
* ],
|
|
230
|
-
* feeToken: '
|
|
235
|
+
* feeToken: 'tempo1qqsvqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqv0ywuh',
|
|
231
236
|
* transactionIndex: '0x2',
|
|
232
237
|
* from: '0x814e5e0e31016b9a7f138c76b7e7b2bb5c1ab6a6',
|
|
233
238
|
* value: '0x9b6e64a8ec60000',
|
|
@@ -266,7 +271,7 @@ export * as Transaction from './Transaction.js'
|
|
|
266
271
|
* const receipt = TransactionReceipt.fromRpc({
|
|
267
272
|
* status: '0x1',
|
|
268
273
|
* feePayer: '0x...',
|
|
269
|
-
* feeToken: '
|
|
274
|
+
* feeToken: 'tempo1qqsvqqqqqqqqqqqqqqqqqqqqqqqqqqqqqyr9xgnd',
|
|
270
275
|
* // ... other fields
|
|
271
276
|
* } as any)
|
|
272
277
|
* ```
|
|
@@ -287,8 +292,8 @@ export * as TransactionReceipt from './TransactionReceipt.js'
|
|
|
287
292
|
* import { TransactionRequest } from 'ox/tempo'
|
|
288
293
|
*
|
|
289
294
|
* const request = TransactionRequest.toRpc({
|
|
290
|
-
* calls: [{ to: '
|
|
291
|
-
* feeToken: '
|
|
295
|
+
* calls: [{ to: 'tempo1qr90aw47etlt40k2l6atajh7h2lv4l46hcx5uwlp', data: '0xdeadbeef' }],
|
|
296
|
+
* feeToken: 'tempo1qqsvqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqv0ywuh',
|
|
292
297
|
* })
|
|
293
298
|
* ```
|
|
294
299
|
*
|
|
@@ -310,7 +315,7 @@ export * as TransactionRequest from './TransactionRequest.js'
|
|
|
310
315
|
*
|
|
311
316
|
* const envelope = TxEnvelopeTempo.from({
|
|
312
317
|
* chainId: 1,
|
|
313
|
-
* calls: [{ to: '
|
|
318
|
+
* calls: [{ to: 'tempo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj97hme', data: '0xdeadbeef' }],
|
|
314
319
|
* maxFeePerGas: Value.fromGwei('10'),
|
|
315
320
|
* })
|
|
316
321
|
*
|
package/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @internal */
|
|
2
|
-
export const version = '0.
|
|
2
|
+
export const version = '0.14.1'
|