ox 1.8.13 → 1.8.15
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 +52 -0
- package/dist/core/AbiError.d.ts +2 -2
- package/dist/core/AbiError.d.ts.map +1 -1
- package/dist/core/AbiError.js +6 -2
- package/dist/core/AbiError.js.map +1 -1
- package/dist/core/AbiEvent.d.ts +71 -1
- package/dist/core/AbiEvent.d.ts.map +1 -1
- package/dist/core/AbiEvent.js +160 -19
- package/dist/core/AbiEvent.js.map +1 -1
- package/dist/core/AbiFunction.d.ts +1 -1
- package/dist/core/AbiFunction.d.ts.map +1 -1
- package/dist/core/AbiFunction.js +3 -5
- package/dist/core/AbiFunction.js.map +1 -1
- package/dist/core/AbiItem.d.ts.map +1 -1
- package/dist/core/AbiItem.js +18 -8
- package/dist/core/AbiItem.js.map +1 -1
- package/dist/core/Base32.d.ts +3 -3
- package/dist/core/Base32.d.ts.map +1 -1
- package/dist/core/Base32.js +5 -2
- package/dist/core/Base32.js.map +1 -1
- package/dist/core/Bytes.d.ts.map +1 -1
- package/dist/core/Bytes.js +4 -3
- package/dist/core/Bytes.js.map +1 -1
- package/dist/core/Caches.d.ts +1 -2
- package/dist/core/Caches.d.ts.map +1 -1
- package/dist/core/Caches.js +1 -4
- package/dist/core/Caches.js.map +1 -1
- package/dist/core/Cbor.d.ts.map +1 -1
- package/dist/core/Cbor.js +16 -2
- package/dist/core/Cbor.js.map +1 -1
- package/dist/core/CompactSize.d.ts +8 -1
- package/dist/core/CompactSize.d.ts.map +1 -1
- package/dist/core/CompactSize.js +9 -0
- package/dist/core/CompactSize.js.map +1 -1
- package/dist/core/Hex.d.ts.map +1 -1
- package/dist/core/Hex.js +9 -4
- package/dist/core/Hex.js.map +1 -1
- package/dist/core/Rlp.d.ts +9 -2
- package/dist/core/Rlp.d.ts.map +1 -1
- package/dist/core/Rlp.js +51 -8
- package/dist/core/Rlp.js.map +1 -1
- package/dist/core/RpcTransport.d.ts.map +1 -1
- package/dist/core/RpcTransport.js +11 -4
- package/dist/core/RpcTransport.js.map +1 -1
- package/dist/core/Siwe.d.ts.map +1 -1
- package/dist/core/Siwe.js +24 -9
- package/dist/core/Siwe.js.map +1 -1
- package/dist/core/TypedData.d.ts.map +1 -1
- package/dist/core/TypedData.js +13 -9
- package/dist/core/TypedData.js.map +1 -1
- package/dist/core/Value.d.ts.map +1 -1
- package/dist/core/Value.js +5 -3
- package/dist/core/Value.js.map +1 -1
- package/dist/core/internal/abiItem.d.ts +3 -1
- package/dist/core/internal/abiItem.d.ts.map +1 -1
- package/dist/core/internal/abiItem.js +5 -3
- package/dist/core/internal/abiItem.js.map +1 -1
- package/dist/core/internal/caches.d.ts +10 -0
- package/dist/core/internal/caches.d.ts.map +1 -0
- package/dist/core/internal/caches.js +10 -0
- package/dist/core/internal/caches.js.map +1 -0
- package/dist/core/internal/frameNonce.d.ts.map +1 -1
- package/dist/core/internal/frameNonce.js +2 -2
- package/dist/core/internal/frameNonce.js.map +1 -1
- package/dist/erc4337/UserOperation.d.ts +15 -2
- package/dist/erc4337/UserOperation.d.ts.map +1 -1
- package/dist/erc4337/UserOperation.js +8 -2
- package/dist/erc4337/UserOperation.js.map +1 -1
- package/dist/erc8021/Attribution.d.ts.map +1 -1
- package/dist/erc8021/Attribution.js +12 -3
- package/dist/erc8021/Attribution.js.map +1 -1
- package/dist/tempo/AccountOperation.d.ts +8 -0
- package/dist/tempo/AccountOperation.d.ts.map +1 -1
- package/dist/tempo/AccountOperation.js +26 -6
- package/dist/tempo/AccountOperation.js.map +1 -1
- package/dist/tempo/SignatureEnvelope.d.ts +4 -4
- package/dist/tempo/SignaturePreAuthorized.d.ts +192 -0
- package/dist/tempo/SignaturePreAuthorized.d.ts.map +1 -0
- package/dist/tempo/SignaturePreAuthorized.js +299 -0
- package/dist/tempo/SignaturePreAuthorized.js.map +1 -0
- package/dist/tempo/Tick.d.ts.map +1 -1
- package/dist/tempo/Tick.js +4 -3
- package/dist/tempo/Tick.js.map +1 -1
- package/dist/tempo/index.d.ts +26 -0
- package/dist/tempo/index.d.ts.map +1 -1
- package/dist/tempo/index.js +26 -0
- package/dist/tempo/index.js.map +1 -1
- package/dist/zod/Address.d.ts.map +1 -1
- package/dist/zod/Address.js +2 -1
- package/dist/zod/Address.js.map +1 -1
- package/dist/zod/FrameRequest.d.ts.map +1 -1
- package/dist/zod/FrameRequest.js +2 -1
- package/dist/zod/FrameRequest.js.map +1 -1
- package/dist/zod/Hex.d.ts.map +1 -1
- package/dist/zod/Hex.js +2 -1
- package/dist/zod/Hex.js.map +1 -1
- package/dist/zod/Solidity.d.ts.map +1 -1
- package/dist/zod/Solidity.js +12 -7
- package/dist/zod/Solidity.js.map +1 -1
- package/dist/zod/TypedData.d.ts +12 -12
- package/package.json +6 -1
- package/src/core/AbiError.ts +33 -22
- package/src/core/AbiEvent.ts +177 -18
- package/src/core/AbiFunction.ts +10 -7
- package/src/core/AbiItem.ts +17 -8
- package/src/core/Base32.ts +8 -3
- package/src/core/Bytes.ts +4 -3
- package/src/core/Caches.ts +1 -6
- package/src/core/Cbor.ts +20 -2
- package/src/core/CompactSize.ts +13 -0
- package/src/core/Hex.ts +10 -5
- package/src/core/Rlp.ts +55 -5
- package/src/core/RpcTransport.ts +11 -4
- package/src/core/Siwe.ts +26 -11
- package/src/core/TypedData.ts +14 -9
- package/src/core/Value.ts +6 -3
- package/src/core/_test/AbiError.test-d.ts +10 -0
- package/src/core/_test/AbiError.test.ts +73 -0
- package/src/core/_test/AbiEvent.fuzz.ts +260 -0
- package/src/core/_test/AbiEvent.snap-d.ts +9 -0
- package/src/core/_test/AbiEvent.test.ts +421 -0
- package/src/core/_test/AbiFunction.snap-d.ts +25 -0
- package/src/core/_test/AbiFunction.test.ts +101 -18
- package/src/core/_test/AbiItem.snap-d.ts +11 -0
- package/src/core/_test/AbiItem.test.ts +155 -1
- package/src/core/_test/Base32.test.ts +16 -0
- package/src/core/_test/Bytes.test.ts +15 -0
- package/src/core/_test/Caches.test.ts +10 -1
- package/src/core/_test/Cbor.test.ts +23 -0
- package/src/core/_test/CompactSize.test.ts +14 -0
- package/src/core/_test/Hex.test.ts +25 -0
- package/src/core/_test/Rlp.test.ts +51 -0
- package/src/core/_test/RpcTransport.test.ts +47 -0
- package/src/core/_test/Siwe.test.ts +28 -0
- package/src/core/_test/TypedData.test.ts +17 -2
- package/src/core/internal/abiItem.ts +16 -7
- package/src/core/internal/caches.ts +12 -0
- package/src/core/internal/frameNonce.ts +3 -4
- package/src/erc4337/UserOperation.ts +30 -3
- package/src/erc4337/_test/UserOperation.test.ts +132 -35
- package/src/erc8021/Attribution.ts +9 -7
- package/src/erc8021/_test/Attribution.test.ts +37 -0
- package/src/tempo/AccountOperation.test.ts +116 -0
- package/src/tempo/AccountOperation.ts +38 -5
- package/src/tempo/AccountSimulation.test.ts +1 -1
- package/src/tempo/SignatureEnvelope.test.ts +12 -0
- package/src/tempo/SignatureEnvelope.ts +4 -4
- package/src/tempo/SignaturePreAuthorized.test-d.ts +29 -0
- package/src/tempo/SignaturePreAuthorized.test.ts +410 -0
- package/src/tempo/SignaturePreAuthorized.ts +370 -0
- package/src/tempo/Tick.test.ts +10 -0
- package/src/tempo/Tick.ts +5 -3
- package/src/tempo/index.ts +26 -0
- package/src/version.ts +1 -1
- package/src/zod/Address.ts +3 -3
- package/src/zod/FrameRequest.ts +3 -4
- package/src/zod/Hex.ts +3 -1
- package/src/zod/Solidity.ts +15 -18
|
@@ -704,12 +704,24 @@ export declare namespace hash {
|
|
|
704
704
|
* @param userOperation - The user operation to convert.
|
|
705
705
|
* @returns The init code.
|
|
706
706
|
*/
|
|
707
|
-
export function toInitCode(
|
|
707
|
+
export function toInitCode(
|
|
708
|
+
userOperation: Partial<UserOperation>,
|
|
709
|
+
options: toInitCode.Options = {},
|
|
710
|
+
): Hex.Hex {
|
|
711
|
+
const { forHash } = options
|
|
708
712
|
const { authorization, factory, factoryData } = userOperation
|
|
709
713
|
if (
|
|
710
714
|
factory === '0x7702' ||
|
|
711
715
|
factory === '0x7702000000000000000000000000000000000000'
|
|
712
716
|
) {
|
|
717
|
+
// Onchain, the EntryPoint detects EIP-7702 by the 20-byte `0x7702` marker
|
|
718
|
+
// and reads the initialization data from `initCode[20:]`.
|
|
719
|
+
if (!forHash)
|
|
720
|
+
return Hex.concat(
|
|
721
|
+
'0x7702000000000000000000000000000000000000',
|
|
722
|
+
factoryData ?? '0x',
|
|
723
|
+
)
|
|
724
|
+
// For the hash, the EntryPoint replaces the marker with the delegate.
|
|
713
725
|
if (!authorization) return '0x7702000000000000000000000000000000000000'
|
|
714
726
|
const delegation = authorization.address
|
|
715
727
|
return Hex.concat(delegation, factoryData ?? '0x')
|
|
@@ -718,6 +730,18 @@ export function toInitCode(userOperation: Partial<UserOperation>): Hex.Hex {
|
|
|
718
730
|
return Hex.concat(factory, factoryData ?? '0x')
|
|
719
731
|
}
|
|
720
732
|
|
|
733
|
+
export declare namespace toInitCode {
|
|
734
|
+
type Options = {
|
|
735
|
+
/**
|
|
736
|
+
* Prepares the init code for hashing: replaces the EIP-7702 `0x7702`
|
|
737
|
+
* marker with the delegate address.
|
|
738
|
+
*/
|
|
739
|
+
forHash?: boolean | undefined
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
type ErrorType = Hex.concat.ErrorType | Errors.GlobalErrorType
|
|
743
|
+
}
|
|
744
|
+
|
|
721
745
|
/**
|
|
722
746
|
* Transforms a User Operation into "packed" format.
|
|
723
747
|
*
|
|
@@ -766,7 +790,7 @@ export function toPacked(
|
|
|
766
790
|
verificationGasLimit || 0n,
|
|
767
791
|
callGasLimit || 0n,
|
|
768
792
|
)
|
|
769
|
-
const initCode = toInitCode(userOperation)
|
|
793
|
+
const initCode = toInitCode(userOperation, { forHash: options.forHash })
|
|
770
794
|
const gasFees = packUint128Pair(
|
|
771
795
|
maxPriorityFeePerGas || 0n,
|
|
772
796
|
maxFeePerGas || 0n,
|
|
@@ -806,7 +830,10 @@ export function toPacked(
|
|
|
806
830
|
export declare namespace toPacked {
|
|
807
831
|
/** Packing options. */
|
|
808
832
|
export type Options = {
|
|
809
|
-
/**
|
|
833
|
+
/**
|
|
834
|
+
* Prepares for hashing: omits the paymaster signature while retaining its
|
|
835
|
+
* marker, and replaces the EIP-7702 `initCode` marker with the delegate.
|
|
836
|
+
*/
|
|
810
837
|
forHash?: boolean | undefined
|
|
811
838
|
}
|
|
812
839
|
|
|
@@ -912,6 +912,62 @@ describe('toPacked', () => {
|
|
|
912
912
|
).toMatchInlineSnapshot(`"0x004122e325a297439656"`)
|
|
913
913
|
})
|
|
914
914
|
})
|
|
915
|
+
|
|
916
|
+
describe('eip7702', () => {
|
|
917
|
+
const userOperation = {
|
|
918
|
+
authorization: {
|
|
919
|
+
address: '0x9f1fdab6458c5fc642fa0f4c5af7473c46837357',
|
|
920
|
+
chainId: 1,
|
|
921
|
+
nonce: 69n,
|
|
922
|
+
yParity: 0,
|
|
923
|
+
r: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
924
|
+
s: '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
925
|
+
},
|
|
926
|
+
callData: '0xdeadbeef',
|
|
927
|
+
callGasLimit: 6942069n,
|
|
928
|
+
factory: '0x7702',
|
|
929
|
+
factoryData: '0xcafebabe',
|
|
930
|
+
maxFeePerGas: 69420n,
|
|
931
|
+
maxPriorityFeePerGas: 69n,
|
|
932
|
+
nonce: 0n,
|
|
933
|
+
preVerificationGas: 6942069n,
|
|
934
|
+
sender: '0x1234567890123456789012345678901234567890',
|
|
935
|
+
signature: '0x',
|
|
936
|
+
verificationGasLimit: 6942069n,
|
|
937
|
+
} as const satisfies UserOperation.UserOperation<'0.8', true>
|
|
938
|
+
|
|
939
|
+
test('default: keeps the EntryPoint `0x7702` initCode marker', () => {
|
|
940
|
+
const packed = UserOperation.toPacked(userOperation)
|
|
941
|
+
expect(packed).toMatchInlineSnapshot(`
|
|
942
|
+
{
|
|
943
|
+
"accountGasLimits": "0x0000000000000000000000000069ed750000000000000000000000000069ed75",
|
|
944
|
+
"callData": "0xdeadbeef",
|
|
945
|
+
"gasFees": "0x0000000000000000000000000000004500000000000000000000000000010f2c",
|
|
946
|
+
"initCode": "0x7702000000000000000000000000000000000000cafebabe",
|
|
947
|
+
"nonce": 0n,
|
|
948
|
+
"paymasterAndData": "0x",
|
|
949
|
+
"preVerificationGas": 6942069n,
|
|
950
|
+
"sender": "0x1234567890123456789012345678901234567890",
|
|
951
|
+
"signature": "0x",
|
|
952
|
+
}
|
|
953
|
+
`)
|
|
954
|
+
const { factory, factoryData } = UserOperation.fromPacked(packed)
|
|
955
|
+
expect({ factory, factoryData }).toMatchInlineSnapshot(`
|
|
956
|
+
{
|
|
957
|
+
"factory": "0x7702000000000000000000000000000000000000",
|
|
958
|
+
"factoryData": "0xcafebabe",
|
|
959
|
+
}
|
|
960
|
+
`)
|
|
961
|
+
})
|
|
962
|
+
|
|
963
|
+
test('options: forHash', () => {
|
|
964
|
+
expect(
|
|
965
|
+
UserOperation.toPacked(userOperation, { forHash: true }).initCode,
|
|
966
|
+
).toMatchInlineSnapshot(
|
|
967
|
+
`"0x9f1fdab6458c5fc642fa0f4c5af7473c46837357cafebabe"`,
|
|
968
|
+
)
|
|
969
|
+
})
|
|
970
|
+
})
|
|
915
971
|
})
|
|
916
972
|
|
|
917
973
|
describe('toInitCode', () => {
|
|
@@ -965,55 +1021,96 @@ describe('toInitCode', () => {
|
|
|
965
1021
|
).toBe('0x7702000000000000000000000000000000000000')
|
|
966
1022
|
})
|
|
967
1023
|
|
|
968
|
-
test('
|
|
1024
|
+
test('options: forHash: EIP-7702 factory with authorization and no factoryData', () => {
|
|
969
1025
|
expect(
|
|
970
|
-
UserOperation.toInitCode(
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
1026
|
+
UserOperation.toInitCode(
|
|
1027
|
+
{
|
|
1028
|
+
factory: '0x7702',
|
|
1029
|
+
factoryData: undefined,
|
|
1030
|
+
authorization: {
|
|
1031
|
+
address: '0x9f1fdab6458c5fc642fa0f4c5af7473c46837357',
|
|
1032
|
+
chainId: 1,
|
|
1033
|
+
nonce: 69n,
|
|
1034
|
+
yParity: 0,
|
|
1035
|
+
r: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1036
|
+
s: '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1037
|
+
},
|
|
980
1038
|
},
|
|
981
|
-
|
|
1039
|
+
{ forHash: true },
|
|
1040
|
+
),
|
|
982
1041
|
).toBe('0x9f1fdab6458c5fc642fa0f4c5af7473c46837357')
|
|
983
1042
|
})
|
|
984
1043
|
|
|
985
|
-
test('
|
|
1044
|
+
test('options: forHash: EIP-7702 factory with authorization and factoryData', () => {
|
|
986
1045
|
expect(
|
|
987
|
-
UserOperation.toInitCode(
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
1046
|
+
UserOperation.toInitCode(
|
|
1047
|
+
{
|
|
1048
|
+
factory: '0x7702',
|
|
1049
|
+
factoryData: '0xdeadbeef',
|
|
1050
|
+
authorization: {
|
|
1051
|
+
address: '0x9f1fdab6458c5fc642fa0f4c5af7473c46837357',
|
|
1052
|
+
chainId: 1,
|
|
1053
|
+
nonce: 69n,
|
|
1054
|
+
yParity: 0,
|
|
1055
|
+
r: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1056
|
+
s: '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1057
|
+
},
|
|
997
1058
|
},
|
|
998
|
-
|
|
1059
|
+
{ forHash: true },
|
|
1060
|
+
),
|
|
999
1061
|
).toBe('0x9f1fdab6458c5fc642fa0f4c5af7473c46837357deadbeef')
|
|
1000
1062
|
})
|
|
1001
1063
|
|
|
1002
|
-
test('
|
|
1064
|
+
test('options: forHash: EIP-7702 factory (full form) with authorization and factoryData', () => {
|
|
1065
|
+
expect(
|
|
1066
|
+
UserOperation.toInitCode(
|
|
1067
|
+
{
|
|
1068
|
+
factory: '0x7702000000000000000000000000000000000000',
|
|
1069
|
+
factoryData: '0xcafebabe',
|
|
1070
|
+
authorization: {
|
|
1071
|
+
address: '0x1234567890123456789012345678901234567890',
|
|
1072
|
+
chainId: 1,
|
|
1073
|
+
nonce: 42n,
|
|
1074
|
+
yParity: 1,
|
|
1075
|
+
r: '0x000000000000000000000000000000000000000000000000000000000000007b',
|
|
1076
|
+
s: '0x00000000000000000000000000000000000000000000000000000000000001c8',
|
|
1077
|
+
},
|
|
1078
|
+
},
|
|
1079
|
+
{ forHash: true },
|
|
1080
|
+
),
|
|
1081
|
+
).toBe('0x1234567890123456789012345678901234567890cafebabe')
|
|
1082
|
+
})
|
|
1083
|
+
|
|
1084
|
+
test('behavior: EIP-7702 factory with authorization packs the 20-byte marker', () => {
|
|
1085
|
+
const authorization = {
|
|
1086
|
+
address: '0x9f1fdab6458c5fc642fa0f4c5af7473c46837357',
|
|
1087
|
+
chainId: 1,
|
|
1088
|
+
nonce: 69n,
|
|
1089
|
+
yParity: 0,
|
|
1090
|
+
r: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1091
|
+
s: '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1092
|
+
} as const
|
|
1093
|
+
expect(
|
|
1094
|
+
UserOperation.toInitCode({
|
|
1095
|
+
factory: '0x7702',
|
|
1096
|
+
factoryData: undefined,
|
|
1097
|
+
authorization,
|
|
1098
|
+
}),
|
|
1099
|
+
).toBe('0x7702000000000000000000000000000000000000')
|
|
1100
|
+
expect(
|
|
1101
|
+
UserOperation.toInitCode({
|
|
1102
|
+
factory: '0x7702',
|
|
1103
|
+
factoryData: '0xdeadbeef',
|
|
1104
|
+
authorization,
|
|
1105
|
+
}),
|
|
1106
|
+
).toBe('0x7702000000000000000000000000000000000000deadbeef')
|
|
1003
1107
|
expect(
|
|
1004
1108
|
UserOperation.toInitCode({
|
|
1005
1109
|
factory: '0x7702000000000000000000000000000000000000',
|
|
1006
|
-
factoryData: '
|
|
1007
|
-
authorization
|
|
1008
|
-
address: '0x1234567890123456789012345678901234567890',
|
|
1009
|
-
chainId: 1,
|
|
1010
|
-
nonce: 42n,
|
|
1011
|
-
yParity: 1,
|
|
1012
|
-
r: '0x000000000000000000000000000000000000000000000000000000000000007b',
|
|
1013
|
-
s: '0x00000000000000000000000000000000000000000000000000000000000001c8',
|
|
1014
|
-
},
|
|
1110
|
+
factoryData: '0xdeadbeef',
|
|
1111
|
+
authorization,
|
|
1015
1112
|
}),
|
|
1016
|
-
).toBe('
|
|
1113
|
+
).toBe('0x7702000000000000000000000000000000000000deadbeef')
|
|
1017
1114
|
})
|
|
1018
1115
|
})
|
|
1019
1116
|
|
|
@@ -354,6 +354,8 @@ function decodeCodesTail(
|
|
|
354
354
|
|
|
355
355
|
const codesEnd = codesLengthStart
|
|
356
356
|
const codesStart = codesEnd - codesLength
|
|
357
|
+
// `Hex.slice` clamps a negative start that runs past the beginning of `data`.
|
|
358
|
+
if (Hex.size(data) + codesStart < 0) return undefined
|
|
357
359
|
const codesHex = Hex.slice(data, codesStart, codesEnd)
|
|
358
360
|
const codesString = Hex.toString(codesHex)
|
|
359
361
|
const codes = codesString.length > 0 ? codesString.split(',') : []
|
|
@@ -472,16 +474,16 @@ function schema2ToDataSuffix(attribution: AttributionSchemaId2): Hex.Hex {
|
|
|
472
474
|
|
|
473
475
|
function schema2FromData(data: Hex.Hex): AttributionSchemaId2 | undefined {
|
|
474
476
|
// cborLength is 2 bytes before schema ID
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
)
|
|
477
|
+
const cborLengthStart = -ercSuffixSize - 1 - 2
|
|
478
|
+
const cborLengthEnd = -ercSuffixSize - 1
|
|
479
|
+
if (Hex.size(data) + cborLengthStart < 0) return undefined
|
|
480
|
+
const cborLengthHex = Hex.slice(data, cborLengthStart, cborLengthEnd)
|
|
480
481
|
const cborLength = Hex.toNumber(cborLengthHex)
|
|
481
482
|
|
|
482
483
|
// Extract CBOR data
|
|
483
|
-
const cborStart =
|
|
484
|
-
|
|
484
|
+
const cborStart = cborLengthStart - cborLength
|
|
485
|
+
if (Hex.size(data) + cborStart < 0) return undefined
|
|
486
|
+
const cborEnd = cborLengthStart
|
|
485
487
|
const cborHex = Hex.slice(data, cborStart, cborEnd)
|
|
486
488
|
|
|
487
489
|
// Decode CBOR
|
|
@@ -442,6 +442,24 @@ describe('fromData', () => {
|
|
|
442
442
|
|
|
443
443
|
expect(result).toBeUndefined()
|
|
444
444
|
})
|
|
445
|
+
|
|
446
|
+
test('codesLength claims more bytes than are available', () => {
|
|
447
|
+
// codesLength 0xff with no codes bytes before it
|
|
448
|
+
const input = '0xff0080218021802180218021802180218021'
|
|
449
|
+
|
|
450
|
+
const result = Attribution.fromData(input)
|
|
451
|
+
|
|
452
|
+
expect(result).toBeUndefined()
|
|
453
|
+
})
|
|
454
|
+
|
|
455
|
+
test('codesLength overruns into unrelated leading bytes', () => {
|
|
456
|
+
// codesLength 0x0a with only 4 bytes before it
|
|
457
|
+
const input = '0xdeadbeef0a0080218021802180218021802180218021'
|
|
458
|
+
|
|
459
|
+
const result = Attribution.fromData(input)
|
|
460
|
+
|
|
461
|
+
expect(result).toBeUndefined()
|
|
462
|
+
})
|
|
445
463
|
})
|
|
446
464
|
})
|
|
447
465
|
|
|
@@ -768,5 +786,24 @@ describe('schema 2 (CBOR-encoded)', () => {
|
|
|
768
786
|
expect(parsed).toEqual(attribution)
|
|
769
787
|
},
|
|
770
788
|
)
|
|
789
|
+
|
|
790
|
+
test('cborLength field missing', () => {
|
|
791
|
+
// 18 bytes: one short of the 2-byte cborLength schema 2 needs
|
|
792
|
+
const input = '0x000280218021802180218021802180218021'
|
|
793
|
+
|
|
794
|
+
const result = Attribution.fromData(input)
|
|
795
|
+
|
|
796
|
+
expect(result).toBeUndefined()
|
|
797
|
+
})
|
|
798
|
+
|
|
799
|
+
test('cborLength claims more bytes than are available', () => {
|
|
800
|
+
// cborLength 0x000c with only the 11-byte `{ a: 'baseapp' }` map before it
|
|
801
|
+
const input =
|
|
802
|
+
'0xa161616762617365617070000c0280218021802180218021802180218021'
|
|
803
|
+
|
|
804
|
+
const result = Attribution.fromData(input)
|
|
805
|
+
|
|
806
|
+
expect(result).toBeUndefined()
|
|
807
|
+
})
|
|
771
808
|
})
|
|
772
809
|
})
|
|
@@ -391,6 +391,83 @@ describe('serializeKeyAuthorization', () => {
|
|
|
391
391
|
})
|
|
392
392
|
|
|
393
393
|
describe('serializeTransaction', () => {
|
|
394
|
+
test('access key transactions', async () => {
|
|
395
|
+
const userAddress = '0x4444444444444444444444444444444444444444'
|
|
396
|
+
const results = []
|
|
397
|
+
for (const transaction_ of [
|
|
398
|
+
transaction,
|
|
399
|
+
TxEnvelopeTempo.serialize(TxEnvelopeTempo.deserialize(transaction), {
|
|
400
|
+
format: 'feePayer',
|
|
401
|
+
sender: userAddress,
|
|
402
|
+
}),
|
|
403
|
+
]) {
|
|
404
|
+
const hash = AccountOperation.getHash({
|
|
405
|
+
account,
|
|
406
|
+
config: currentConfig,
|
|
407
|
+
transaction: transaction_,
|
|
408
|
+
type: 'transaction',
|
|
409
|
+
userAddress,
|
|
410
|
+
})
|
|
411
|
+
const selection = await AccountOperation.selectApprovals({
|
|
412
|
+
account,
|
|
413
|
+
approvals: [
|
|
414
|
+
signApproval(owners[0]!, hash),
|
|
415
|
+
signApproval(owners[1]!, hash),
|
|
416
|
+
],
|
|
417
|
+
config: currentConfig,
|
|
418
|
+
hash,
|
|
419
|
+
})
|
|
420
|
+
const operation = AccountOperation.from({
|
|
421
|
+
account,
|
|
422
|
+
approvals: selection.approvals,
|
|
423
|
+
config: currentConfig,
|
|
424
|
+
createdAt: 1,
|
|
425
|
+
hash,
|
|
426
|
+
signatureCount: selection.signatureCount,
|
|
427
|
+
status: 'pending',
|
|
428
|
+
threshold: selection.threshold,
|
|
429
|
+
transaction: transaction_,
|
|
430
|
+
type: 'transaction',
|
|
431
|
+
updatedAt: 1,
|
|
432
|
+
userAddress,
|
|
433
|
+
weight: selection.weight,
|
|
434
|
+
})
|
|
435
|
+
const value = TxEnvelopeTempo.deserialize(
|
|
436
|
+
AccountOperation.serializeTransaction(operation, {
|
|
437
|
+
approvals: selection.selectedApprovals,
|
|
438
|
+
}),
|
|
439
|
+
)
|
|
440
|
+
const { signature } = value
|
|
441
|
+
if (signature?.type !== 'keychain') throw new Error('expected keychain')
|
|
442
|
+
results.push({
|
|
443
|
+
from: value.from,
|
|
444
|
+
innerAccount:
|
|
445
|
+
signature.inner.type === 'configurable'
|
|
446
|
+
? signature.inner.account
|
|
447
|
+
: undefined,
|
|
448
|
+
userAddress: signature.userAddress,
|
|
449
|
+
version: signature.version,
|
|
450
|
+
})
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
expect(results).toMatchInlineSnapshot(`
|
|
454
|
+
[
|
|
455
|
+
{
|
|
456
|
+
"from": "0x4444444444444444444444444444444444444444",
|
|
457
|
+
"innerAccount": "0xb3cc0b31026c7a54a9c45e468c674722c3c5b3b5",
|
|
458
|
+
"userAddress": "0x4444444444444444444444444444444444444444",
|
|
459
|
+
"version": "v2",
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
"from": "0x4444444444444444444444444444444444444444",
|
|
463
|
+
"innerAccount": "0xb3cc0b31026c7a54a9c45e468c674722c3c5b3b5",
|
|
464
|
+
"userAddress": "0x4444444444444444444444444444444444444444",
|
|
465
|
+
"version": "v2",
|
|
466
|
+
},
|
|
467
|
+
]
|
|
468
|
+
`)
|
|
469
|
+
})
|
|
470
|
+
|
|
394
471
|
test('current and initial transactions', async () => {
|
|
395
472
|
const results = []
|
|
396
473
|
for (const applicableConfig of [currentConfig, config]) {
|
|
@@ -593,6 +670,45 @@ describe('serializeTransaction', () => {
|
|
|
593
670
|
})
|
|
594
671
|
|
|
595
672
|
describe('from', () => {
|
|
673
|
+
test('error: access key transaction hash without userAddress', () => {
|
|
674
|
+
const userAddress = '0x4444444444444444444444444444444444444444'
|
|
675
|
+
const hash = AccountOperation.getHash({
|
|
676
|
+
account,
|
|
677
|
+
config: currentConfig,
|
|
678
|
+
transaction,
|
|
679
|
+
type: 'transaction',
|
|
680
|
+
userAddress,
|
|
681
|
+
})
|
|
682
|
+
const base = {
|
|
683
|
+
account,
|
|
684
|
+
approvals: [],
|
|
685
|
+
config: currentConfig,
|
|
686
|
+
createdAt: 1,
|
|
687
|
+
hash,
|
|
688
|
+
signatureCount: 0,
|
|
689
|
+
status: 'pending',
|
|
690
|
+
threshold: 2,
|
|
691
|
+
transaction,
|
|
692
|
+
type: 'transaction',
|
|
693
|
+
updatedAt: 1,
|
|
694
|
+
weight: 0,
|
|
695
|
+
} as const
|
|
696
|
+
|
|
697
|
+
expect(() =>
|
|
698
|
+
AccountOperation.from(base),
|
|
699
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
700
|
+
`[AccountOperation.InvalidOperationError: Invalid account operation: hash does not match the operation payload.]`,
|
|
701
|
+
)
|
|
702
|
+
expect(() =>
|
|
703
|
+
AccountOperation.from({ ...base, userAddress: account }),
|
|
704
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
705
|
+
`[AccountOperation.InvalidOperationError: Invalid account operation: a configurable account cannot be its own access key.]`,
|
|
706
|
+
)
|
|
707
|
+
expect(AccountOperation.from({ ...base, userAddress }).userAddress).toBe(
|
|
708
|
+
userAddress,
|
|
709
|
+
)
|
|
710
|
+
})
|
|
711
|
+
|
|
596
712
|
test('transaction states', () => {
|
|
597
713
|
const pending = AccountOperation.from(transactionPending)
|
|
598
714
|
const submitting = AccountOperation.from({
|
|
@@ -43,6 +43,12 @@ export type TransactionOperation<quantity = bigint> = Base<quantity> & {
|
|
|
43
43
|
transactionHash?: Hex.Hex | undefined
|
|
44
44
|
/** Operation kind. */
|
|
45
45
|
type: 'transaction'
|
|
46
|
+
/**
|
|
47
|
+
* Parent account when the configurable account signs as its access key
|
|
48
|
+
* (TIP-1111). The transaction is then sent from it with a keychain V2
|
|
49
|
+
* signature wrapping the owner quorum.
|
|
50
|
+
*/
|
|
51
|
+
userAddress?: Address.Address | undefined
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
/** Account key authorization approval operation. */
|
|
@@ -94,6 +100,7 @@ export function getHash(options: getHash.Options): Hex.Hex {
|
|
|
94
100
|
options.type === 'transaction'
|
|
95
101
|
? TxEnvelopeTempo.getSignPayload(
|
|
96
102
|
TxEnvelopeTempo.deserialize(options.transaction),
|
|
103
|
+
{ from: options.userAddress },
|
|
97
104
|
)
|
|
98
105
|
: KeyAuthorization_.getSignPayload(
|
|
99
106
|
KeyAuthorization_.deserialize(options.keyAuthorization),
|
|
@@ -124,6 +131,8 @@ export declare namespace getHash {
|
|
|
124
131
|
transaction: TxEnvelopeTempo.Serialized
|
|
125
132
|
/** Operation kind. */
|
|
126
133
|
type: 'transaction'
|
|
134
|
+
/** Parent account when the configurable account signs as its access key. */
|
|
135
|
+
userAddress?: Address.Address | undefined
|
|
127
136
|
}
|
|
128
137
|
)
|
|
129
138
|
|
|
@@ -333,17 +342,26 @@ export function serializeTransaction(
|
|
|
333
342
|
assertApproval(value.account, approval, value.config),
|
|
334
343
|
)
|
|
335
344
|
assertRetainedApprovals(value, approvals)
|
|
345
|
+
const { userAddress } = value
|
|
336
346
|
const signatures = SignatureEnvelope.sortApprovals({
|
|
337
347
|
account: value.account,
|
|
338
348
|
config: value.config,
|
|
339
|
-
payload: TxEnvelopeTempo.getSignPayload(envelope),
|
|
349
|
+
payload: TxEnvelopeTempo.getSignPayload(envelope, { from: userAddress }),
|
|
340
350
|
signatures: approvals,
|
|
341
351
|
})
|
|
342
|
-
const
|
|
352
|
+
const configurable = SignatureEnvelope.from({
|
|
343
353
|
account: value.account,
|
|
344
354
|
config: value.config,
|
|
345
355
|
signatures,
|
|
346
356
|
})
|
|
357
|
+
const signature = userAddress
|
|
358
|
+
? SignatureEnvelope.from({
|
|
359
|
+
inner: configurable,
|
|
360
|
+
type: 'keychain',
|
|
361
|
+
userAddress,
|
|
362
|
+
version: 'v2',
|
|
363
|
+
})
|
|
364
|
+
: configurable
|
|
347
365
|
return TxEnvelopeTempo.serialize(
|
|
348
366
|
envelope,
|
|
349
367
|
value.transaction.startsWith(TxEnvelopeTempo.feePayerMagic)
|
|
@@ -808,14 +826,27 @@ function assertTransaction(operation: TransactionOperation): void {
|
|
|
808
826
|
throw new InvalidOperationError({
|
|
809
827
|
reason: 'transaction must not contain an outer sender signature',
|
|
810
828
|
})
|
|
829
|
+
const { userAddress } = operation
|
|
830
|
+
if (userAddress !== undefined) {
|
|
831
|
+
if (!Address.validate(userAddress) || Hex.toBigInt(userAddress) === 0n)
|
|
832
|
+
throw new InvalidOperationError({ reason: 'userAddress is invalid' })
|
|
833
|
+
if (userAddress.toLowerCase() === operation.account.toLowerCase())
|
|
834
|
+
throw new InvalidOperationError({
|
|
835
|
+
reason: 'a configurable account cannot be its own access key',
|
|
836
|
+
})
|
|
837
|
+
}
|
|
838
|
+
const sender = userAddress ?? operation.account
|
|
811
839
|
if (
|
|
812
840
|
transaction.from &&
|
|
813
|
-
transaction.from.toLowerCase() !==
|
|
841
|
+
transaction.from.toLowerCase() !== sender.toLowerCase()
|
|
814
842
|
)
|
|
815
843
|
throw new InvalidOperationError({
|
|
816
844
|
reason: 'transaction sender does not match the operation account',
|
|
817
845
|
})
|
|
818
|
-
assertOperationHash(
|
|
846
|
+
assertOperationHash(
|
|
847
|
+
operation,
|
|
848
|
+
TxEnvelopeTempo.getSignPayload(transaction, { from: userAddress }),
|
|
849
|
+
)
|
|
819
850
|
const normalized = TxEnvelopeTempo.serialize(
|
|
820
851
|
transaction,
|
|
821
852
|
feePayer
|
|
@@ -844,12 +875,14 @@ function assertKeyAuthorization(
|
|
|
844
875
|
submissionId?: unknown
|
|
845
876
|
transaction?: unknown
|
|
846
877
|
transactionHash?: unknown
|
|
878
|
+
userAddress?: unknown
|
|
847
879
|
}
|
|
848
880
|
if (
|
|
849
881
|
transactionFields.expiresAt !== undefined ||
|
|
850
882
|
transactionFields.submissionId !== undefined ||
|
|
851
883
|
transactionFields.transaction !== undefined ||
|
|
852
|
-
transactionFields.transactionHash !== undefined
|
|
884
|
+
transactionFields.transactionHash !== undefined ||
|
|
885
|
+
transactionFields.userAddress !== undefined
|
|
853
886
|
)
|
|
854
887
|
throw new InvalidOperationError({
|
|
855
888
|
reason: 'key authorization operations cannot contain transaction fields',
|
|
@@ -107,7 +107,7 @@ describe('fromRpc', () => {
|
|
|
107
107
|
expect(() =>
|
|
108
108
|
AccountSimulation.fromRpc({ ...rpc, config: noncanonical }),
|
|
109
109
|
).toThrowErrorMatchingInlineSnapshot(
|
|
110
|
-
`[
|
|
110
|
+
`[Rlp.NonCanonicalError: RLP payload is not canonically encoded: single byte \`0x00\` is wrapped in an explicit length prefix instead of being encoded as itself.]`,
|
|
111
111
|
)
|
|
112
112
|
})
|
|
113
113
|
})
|
|
@@ -1059,6 +1059,18 @@ describe('from', () => {
|
|
|
1059
1059
|
expect(envelope.type).toBe('keychain')
|
|
1060
1060
|
})
|
|
1061
1061
|
|
|
1062
|
+
test('behavior: defaults version to v2', () => {
|
|
1063
|
+
const envelope = SignatureEnvelope.from({
|
|
1064
|
+
inner: SignatureEnvelope.from(signature_secp256k1),
|
|
1065
|
+
userAddress: '0x1234567890123456789012345678901234567890',
|
|
1066
|
+
})
|
|
1067
|
+
|
|
1068
|
+
expect(envelope).toMatchObject({ version: 'v2' })
|
|
1069
|
+
expect(
|
|
1070
|
+
Hex.slice(SignatureEnvelope.serialize(envelope), 0, 1),
|
|
1071
|
+
).toMatchInlineSnapshot(`"0x04"`)
|
|
1072
|
+
})
|
|
1073
|
+
|
|
1062
1074
|
test('behavior: computes keyId from p256 inner publicKey', () => {
|
|
1063
1075
|
const envelope = SignatureEnvelope.from({
|
|
1064
1076
|
userAddress: '0x1234567890123456789012345678901234567890',
|
|
@@ -110,7 +110,7 @@ export type GetType<
|
|
|
110
110
|
*
|
|
111
111
|
* - **keychain** (type `0x03` V1, `0x04` V2): Access key signature that wraps an inner signature
|
|
112
112
|
* (secp256k1, p256, or webAuthn). Format: type byte + user_address (20 bytes) + inner signature.
|
|
113
|
-
* V2 binds the signature to the user account via `keccak256(sigHash || userAddress)`.
|
|
113
|
+
* V2 binds the signature to the user account via `keccak256(0x04 || sigHash || userAddress)`.
|
|
114
114
|
* The protocol validates the access key authorization via the AccountKeychain precompile.
|
|
115
115
|
*
|
|
116
116
|
* - **configurable** (type `0x05`): Configurable account signature carrying the account address,
|
|
@@ -145,8 +145,8 @@ export type PrimitiveRpc = OneOf<Secp256k1Rpc | P256Rpc | WebAuthnRpc>
|
|
|
145
145
|
* Keychain signature version.
|
|
146
146
|
*
|
|
147
147
|
* - `'v1'`: Legacy format. Inner signature signs the raw `sig_hash` directly. Deprecated at T1C.
|
|
148
|
-
* - `'v2'`: Inner signature signs `keccak256(sig_hash || user_address)`, binding the
|
|
149
|
-
* to the specific user account.
|
|
148
|
+
* - `'v2'`: Inner signature signs `keccak256(0x04 || sig_hash || user_address)`, binding the
|
|
149
|
+
* signature to the specific user account.
|
|
150
150
|
*/
|
|
151
151
|
export type KeychainVersion = 'v1' | 'v2'
|
|
152
152
|
|
|
@@ -158,7 +158,7 @@ export type Keychain<numberType = number> = {
|
|
|
158
158
|
type: 'keychain'
|
|
159
159
|
/** Root account address that this transaction is being executed for */
|
|
160
160
|
userAddress: Address.Address
|
|
161
|
-
/** Keychain signature version. @default '
|
|
161
|
+
/** Keychain signature version. @default 'v2' */
|
|
162
162
|
version?: KeychainVersion | undefined
|
|
163
163
|
}
|
|
164
164
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { expectTypeOf, test } from 'vp/test'
|
|
2
|
+
import type * as Hex from '../core/Hex.js'
|
|
3
|
+
import type * as KeyAuthorization from './KeyAuthorization.js'
|
|
4
|
+
import type * as SignatureEnvelope from './SignatureEnvelope.js'
|
|
5
|
+
import * as SignaturePreAuthorized from './SignaturePreAuthorized.js'
|
|
6
|
+
|
|
7
|
+
test('magicBytes', () => {
|
|
8
|
+
expectTypeOf(
|
|
9
|
+
SignaturePreAuthorized.magicBytes,
|
|
10
|
+
).toEqualTypeOf<'0x1165116511651165116511651165116511651165116511651165116511651165'>()
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test('unwrap', () => {
|
|
14
|
+
const unwrapped = SignaturePreAuthorized.unwrap('0x')
|
|
15
|
+
expectTypeOf(
|
|
16
|
+
unwrapped.keyAuthorization,
|
|
17
|
+
).toEqualTypeOf<KeyAuthorization.Signed>()
|
|
18
|
+
expectTypeOf(unwrapped.signature).toEqualTypeOf<SignatureEnvelope.Keychain>()
|
|
19
|
+
expectTypeOf(
|
|
20
|
+
SignaturePreAuthorized.from('0x'),
|
|
21
|
+
).toEqualTypeOf<SignaturePreAuthorized.Unwrapped>()
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('wrap', () => {
|
|
25
|
+
expectTypeOf(SignaturePreAuthorized.wrap).returns.toEqualTypeOf<Hex.Hex>()
|
|
26
|
+
expectTypeOf(SignaturePreAuthorized.wrap)
|
|
27
|
+
.parameter(0)
|
|
28
|
+
.toEqualTypeOf<SignaturePreAuthorized.Unwrapped>()
|
|
29
|
+
})
|