@agoric/orchestration 0.1.1-dev-d756c83.0.d756c83 → 0.1.1-dev-e9efaa1.0.e9efaa1

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.
@@ -11,48 +11,48 @@
11
11
  * Some stylistic changes have also been made to conform to our code style.
12
12
  */
13
13
 
14
- import type { TypedDataToPrimitiveTypes } from 'abitype';
15
- import type {
16
- Address,
17
- TypedData,
18
- TypedDataDefinition,
19
- TypedDataDomain,
20
- } from 'viem';
21
- import type { TypedDataParameter } from '../abitype.ts';
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
22
 
23
23
  const PERMIT2_DOMAIN_NAME = 'Permit2';
24
24
 
25
25
  // TODO: disallow witness type field being another Permit field name
26
- interface WitnessDefinition<
27
- T extends TypedData = TypedData,
28
- TD extends TypedDataParameter<string, Extract<keyof T, string>> =
29
- TypedDataParameter<'witness', Extract<keyof T, string>>,
30
- > {
31
- witnessField: TD;
32
- witnessTypes: T;
33
- }
34
-
35
- export interface Witness<
36
- T extends TypedData = TypedData,
37
- TD extends TypedDataParameter<string, Extract<keyof T, string>> =
38
- TypedDataParameter<'witness', Extract<keyof T, string>>,
39
- > extends WitnessDefinition<T, TD> {
40
- witness: TypedDataToPrimitiveTypes<T>[TD['type']];
41
- }
26
+ ;
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+ ;
36
+
37
+
38
+
39
+
40
+
41
+
42
42
 
43
43
  /**
44
44
  * Helper to help caller check that the `data` matches the inferred witness types
45
45
  *
46
46
  * @see {@link https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-4.html#the-noinfer-utility-type}
47
47
  */
48
- export function makeWitness<
49
- T extends TypedData,
50
- TD extends TypedDataParameter<string, Extract<keyof T, string>>,
51
- >(
52
- data: NoInfer<TypedDataToPrimitiveTypes<T>[TD['type']]>,
53
- types: T,
54
- typeParam: TD,
55
- ): Witness<T, TD> {
48
+ export function makeWitness(
49
+
50
+
51
+
52
+ data ,
53
+ types ,
54
+ typeParam ,
55
+ ) {
56
56
  return {
57
57
  witness: data,
58
58
  witnessTypes: types,
@@ -60,134 +60,134 @@ export function makeWitness<
60
60
  };
61
61
  }
62
62
 
63
- export type TokenPermissions = {
64
- token: Address;
65
- amount: bigint;
66
- };
67
-
68
- export type PermitTransferFrom = {
69
- permitted: TokenPermissions;
70
- spender: Address;
71
- nonce: bigint;
72
- deadline: bigint;
73
- };
74
-
75
- export type PermitBatchTransferFrom = {
76
- permitted: readonly TokenPermissions[];
77
- spender: Address;
78
- nonce: bigint;
79
- deadline: bigint;
80
- };
63
+ ;
64
+
65
+
66
+
67
+
68
+ ;
69
+
70
+
71
+
72
+
73
+
74
+
75
+ ;
76
+
77
+
78
+
79
+
80
+
81
81
 
82
82
  const Permit2DomainTypeParams = [
83
83
  { name: 'name', type: 'string' },
84
84
  { name: 'chainId', type: 'uint256' },
85
85
  { name: 'verifyingContract', type: 'address' },
86
- ] as const satisfies TypedDataParameter[];
86
+ ] ;
87
87
 
88
88
  export const PermitTransferFromTypeParams = [
89
89
  { name: 'permitted', type: 'TokenPermissions' },
90
90
  { name: 'spender', type: 'address' },
91
91
  { name: 'nonce', type: 'uint256' },
92
92
  { name: 'deadline', type: 'uint256' },
93
- ] as const satisfies TypedDataParameter[];
93
+ ] ;
94
94
 
95
95
  export const PermitBatchTransferFromTypeParams = [
96
96
  { name: 'permitted', type: 'TokenPermissions[]' },
97
97
  { name: 'spender', type: 'address' },
98
98
  { name: 'nonce', type: 'uint256' },
99
99
  { name: 'deadline', type: 'uint256' },
100
- ] as const satisfies TypedDataParameter[];
100
+ ] ;
101
101
 
102
102
  const TokenPermissionTypeParams = [
103
103
  { name: 'token', type: 'address' },
104
104
  { name: 'amount', type: 'uint256' },
105
- ] as const satisfies TypedDataParameter[];
105
+ ] ;
106
106
 
107
107
  export const PermitTransferFromTypes = {
108
108
  EIP712Domain: Permit2DomainTypeParams,
109
109
  PermitTransferFrom: PermitTransferFromTypeParams,
110
110
  TokenPermissions: TokenPermissionTypeParams,
111
- } as const satisfies TypedData;
111
+ } ;
112
112
 
113
113
  export const PermitBatchTransferFromTypes = {
114
114
  EIP712Domain: Permit2DomainTypeParams,
115
115
  PermitBatchTransferFrom: PermitBatchTransferFromTypeParams,
116
116
  TokenPermissions: TokenPermissionTypeParams,
117
- } as const satisfies TypedData;
117
+ } ;
118
118
 
119
- export function permitWitnessTransferFromTypes<
120
- T extends TypedData,
121
- TD extends TypedDataParameter<string, Extract<keyof T, string>> =
122
- TypedDataParameter<'witness', Extract<keyof T, string>>,
123
- >(witness: WitnessDefinition<T, TD>) {
119
+ export function permitWitnessTransferFromTypes(
120
+
121
+
122
+
123
+ witness ) {
124
124
  return {
125
125
  EIP712Domain: Permit2DomainTypeParams,
126
126
  PermitWitnessTransferFrom: [
127
127
  ...PermitTransferFromTypeParams,
128
128
  // Enable runtime type to accept undefined field for base type extraction
129
- ...((witness ? [witness.witnessField] : []) as [TD]),
129
+ ...((witness ? [witness.witnessField] : []) ),
130
130
  ],
131
131
  TokenPermissions: TokenPermissionTypeParams,
132
132
  ...witness?.witnessTypes,
133
- } as const satisfies TypedData;
133
+ } ;
134
134
  }
135
135
 
136
- export function permitBatchWitnessTransferFromTypes<
137
- T extends TypedData,
138
- TD extends TypedDataParameter<string, Extract<keyof T, string>> =
139
- TypedDataParameter<'witness', Extract<keyof T, string>>,
140
- >(witness: WitnessDefinition<T, TD>) {
136
+ export function permitBatchWitnessTransferFromTypes(
137
+
138
+
139
+
140
+ witness ) {
141
141
  return {
142
142
  EIP712Domain: Permit2DomainTypeParams,
143
143
  PermitBatchWitnessTransferFrom: [
144
144
  ...PermitBatchTransferFromTypeParams,
145
145
  // Enable runtime type to accept undefined field for base type extraction
146
- ...((witness ? [witness.witnessField] : []) as [TD]),
146
+ ...((witness ? [witness.witnessField] : []) ),
147
147
  ],
148
148
  TokenPermissions: TokenPermissionTypeParams,
149
149
  ...witness?.witnessTypes,
150
- } as const satisfies TypedData;
150
+ } ;
151
151
  }
152
152
 
153
- export type PermitWitnessTransferFrom<
154
- T extends Record<string, unknown>,
155
- TN extends string = 'witness',
156
- > = PermitTransferFrom & { [key in TN]: T };
153
+ ;
154
+
155
+
156
+
157
157
 
158
- export type PermitBatchWitnessTransferFrom<
159
- T extends Record<string, unknown>,
160
- TN extends string = 'witness',
161
- > = PermitBatchTransferFrom & { [key in TN]: T };
158
+ ;
159
+
160
+
161
+
162
162
 
163
163
  export function permit2Domain(
164
- permit2Address: Address,
165
- chainId: number | bigint,
164
+ permit2Address ,
165
+ chainId ,
166
166
  ) {
167
167
  return {
168
168
  name: PERMIT2_DOMAIN_NAME,
169
169
  chainId,
170
170
  verifyingContract: permit2Address,
171
- } as const satisfies TypedDataDomain;
171
+ } ;
172
172
  }
173
173
 
174
174
  // XXX: restore permit to be either PermitTransferFrom or PermitBatchTransferFrom
175
175
  // and remove duplication between the two functions below
176
176
  // Original method was `SignatureTransfer.getPermitData`
177
- export function getPermitWitnessTransferFromData<
178
- T extends TypedData,
179
- TD extends TypedDataParameter<string, Extract<keyof T, string>> =
180
- TypedDataParameter<'witness', Extract<keyof T, string>>,
181
- >(
182
- permit: PermitTransferFrom,
183
- permit2Address: Address,
184
- chainId: number | bigint,
185
- witness: Witness<T, TD>,
186
- ): TypedDataDefinition<
187
- ReturnType<typeof permitWitnessTransferFromTypes<T, TD>>,
188
- 'PermitWitnessTransferFrom',
189
- 'PermitWitnessTransferFrom'
190
- > {
177
+ export function getPermitWitnessTransferFromData(
178
+
179
+
180
+
181
+
182
+ permit ,
183
+ permit2Address ,
184
+ chainId ,
185
+ witness ,
186
+ )
187
+
188
+
189
+
190
+ {
191
191
  // type MessageType = TypedDataToPrimitiveTypes<
192
192
  // ReturnType<typeof permitWitnessTransferFromTypes<T, TD>>
193
193
  // >['PermitWitnessTransferFrom'];
@@ -209,20 +209,20 @@ export function getPermitWitnessTransferFromData<
209
209
  };
210
210
  }
211
211
 
212
- export function getPermitBatchWitnessTransferFromData<
213
- T extends TypedData,
214
- TD extends TypedDataParameter<string, Extract<keyof T, string>> =
215
- TypedDataParameter<'witness', Extract<keyof T, string>>,
216
- >(
217
- permit: PermitBatchTransferFrom,
218
- permit2Address: Address,
219
- chainId: number | bigint,
220
- witness: Witness<T, TD>,
221
- ): TypedDataDefinition<
222
- ReturnType<typeof permitBatchWitnessTransferFromTypes<T, TD>>,
223
- 'PermitBatchWitnessTransferFrom',
224
- 'PermitBatchWitnessTransferFrom'
225
- > {
212
+ export function getPermitBatchWitnessTransferFromData(
213
+
214
+
215
+
216
+
217
+ permit ,
218
+ permit2Address ,
219
+ chainId ,
220
+ witness ,
221
+ )
222
+
223
+
224
+
225
+ {
226
226
  // type MessageType = TypedDataToPrimitiveTypes<
227
227
  // ReturnType<typeof permitBatchWitnessTransferFromTypes<T, TD>>
228
228
  // >['PermitBatchWitnessTransferFrom'];
@@ -4,13 +4,13 @@
4
4
  * This is original code that was adapted for permit2-sdk, unlike @see ./permit2SignatureTransfer.ts
5
5
  */
6
6
 
7
- import type {
8
- AbiFunction,
9
- AbiParameter,
10
- AbiParameterToPrimitiveType,
11
- TypedData,
12
- } from 'abitype';
13
- import type { TypedDataParameter } from '../abitype.ts';
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
14
  import {
15
15
  PermitBatchTransferFromTypeParams,
16
16
  permitBatchWitnessTransferFromTypes,
@@ -20,15 +20,15 @@ import {
20
20
 
21
21
  export const makeWitnessTypeStringExtractor = ({
22
22
  encodeType,
23
- }: {
24
- encodeType: ({
25
- primaryType,
26
- types,
27
- }: {
28
- primaryType: string;
29
- types: TypedData;
30
- }) => string;
31
- }) => {
23
+ }
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+ ) => {
32
32
  const baseTypeStrings = Object.fromEntries(
33
33
  Object.entries({
34
34
  PermitBatchWitnessTransferFrom: permitBatchWitnessTransferFromTypes,
@@ -45,7 +45,7 @@ export const makeWitnessTypeStringExtractor = ({
45
45
  }),
46
46
  );
47
47
 
48
- return function getWitnessTypeString(types: TypedData) {
48
+ return function getWitnessTypeString(types ) {
49
49
  const matchingTypes = Object.keys(types).filter(
50
50
  type => type in baseTypeStrings,
51
51
  );
@@ -73,31 +73,31 @@ export const makeWitnessTypeStringExtractor = ({
73
73
  };
74
74
  };
75
75
 
76
- type MapUnion<U> = {
77
- [K in U extends any ? keyof U : never]: U extends any
78
- ? K extends keyof U
79
- ? U[K]
80
- : never
81
- : never;
82
- };
76
+ ;
77
+
78
+
79
+
80
+
81
+
82
+
83
83
 
84
- export const extractWitnessFieldFromTypes = <
85
- T extends Readonly<TypedDataParameter>,
86
- >(
87
- types:
88
- | {
89
- PermitBatchWitnessTransferFrom: readonly [
90
- ...typeof PermitBatchTransferFromTypeParams,
91
- T,
92
- ];
93
- }
94
- | {
95
- PermitWitnessTransferFrom: readonly [
96
- ...typeof PermitTransferFromTypeParams,
97
- T,
98
- ];
99
- },
100
- ): T => {
84
+ export const extractWitnessFieldFromTypes = (
85
+
86
+
87
+ types
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+ ,
100
+ ) => {
101
101
  const baseTypes = {
102
102
  PermitBatchWitnessTransferFrom: PermitBatchTransferFromTypeParams,
103
103
  PermitWitnessTransferFrom: PermitTransferFromTypeParams,
@@ -105,7 +105,7 @@ export const extractWitnessFieldFromTypes = <
105
105
 
106
106
  const matchingTypes = Object.keys(types).filter(
107
107
  type => type in baseTypes,
108
- ) as (keyof typeof baseTypes)[];
108
+ ) ;
109
109
 
110
110
  if (matchingTypes.length !== 1) {
111
111
  throw new Error(
@@ -114,7 +114,7 @@ export const extractWitnessFieldFromTypes = <
114
114
  }
115
115
 
116
116
  const primaryType = matchingTypes[0];
117
- const candidateType = (types as MapUnion<typeof types>)[primaryType];
117
+ const candidateType = (types )[primaryType];
118
118
  const referenceType = baseTypes[primaryType];
119
119
  if (candidateType.length !== referenceType.length + 1) {
120
120
  throw new Error(
@@ -133,10 +133,10 @@ export const extractWitnessFieldFromTypes = <
133
133
  }
134
134
  }
135
135
 
136
- return candidateType[candidateType.length - 1] as T;
136
+ return candidateType[candidateType.length - 1] ;
137
137
  };
138
138
 
139
- export const isPermit2MessageType = (type: string) => {
139
+ export const isPermit2MessageType = (type ) => {
140
140
  return (
141
141
  type === 'PermitBatchWitnessTransferFrom' ||
142
142
  type === 'PermitWitnessTransferFrom'
@@ -146,9 +146,9 @@ export const isPermit2MessageType = (type: string) => {
146
146
  export const TokenPermissionsComponents = [
147
147
  { name: 'token', type: 'address' },
148
148
  { name: 'amount', type: 'uint256' },
149
- ] as const satisfies AbiParameter[];
149
+ ] ;
150
150
  export const TokenPermissionsInternalTypeName =
151
- 'struct ISignatureTransfer.TokenPermissions' as const;
151
+ 'struct ISignatureTransfer.TokenPermissions' ;
152
152
 
153
153
  export const PermitTransferFromComponents = [
154
154
  {
@@ -159,14 +159,14 @@ export const PermitTransferFromComponents = [
159
159
  },
160
160
  { name: 'nonce', type: 'uint256' },
161
161
  { name: 'deadline', type: 'uint256' },
162
- ] as const satisfies AbiParameter[];
162
+ ] ;
163
163
  export const PermitTransferFromInternalTypeName =
164
- 'struct ISignatureTransfer.PermitTransferFrom' as const;
165
- export type PermitTransferFromStruct = AbiParameterToPrimitiveType<{
166
- type: 'tuple';
167
- internalType: typeof PermitTransferFromInternalTypeName;
168
- components: typeof PermitTransferFromComponents;
169
- }>;
164
+ 'struct ISignatureTransfer.PermitTransferFrom' ;
165
+ ;
166
+
167
+
168
+
169
+
170
170
 
171
171
  export const PermitBatchTransferFromComponents = [
172
172
  {
@@ -177,26 +177,26 @@ export const PermitBatchTransferFromComponents = [
177
177
  },
178
178
  { name: 'nonce', type: 'uint256' },
179
179
  { name: 'deadline', type: 'uint256' },
180
- ] as const satisfies AbiParameter[];
180
+ ] ;
181
181
  export const PermitBatchTransferFromInternalTypeName =
182
- 'struct ISignatureTransfer.PermitBatchTransferFrom' as const;
183
- export type PermitBatchTransferFromStruct = AbiParameterToPrimitiveType<{
184
- type: 'tuple';
185
- internalType: typeof PermitBatchTransferFromInternalTypeName;
186
- components: typeof PermitBatchTransferFromComponents;
187
- }>;
182
+ 'struct ISignatureTransfer.PermitBatchTransferFrom' ;
183
+ ;
184
+
185
+
186
+
187
+
188
188
 
189
189
  export const SignatureTransferDetailsComponents = [
190
190
  { name: 'to', type: 'address' },
191
191
  { name: 'requestedAmount', type: 'uint256' },
192
- ] as const satisfies AbiParameter[];
192
+ ] ;
193
193
  export const SignatureTransferDetailsInternalTypeName =
194
- 'struct ISignatureTransfer.SignatureTransferDetails' as const;
195
- export type SignatureTransferDetailsStruct = AbiParameterToPrimitiveType<{
196
- type: 'tuple';
197
- internalType: typeof SignatureTransferDetailsInternalTypeName;
198
- components: typeof SignatureTransferDetailsComponents;
199
- }>;
194
+ 'struct ISignatureTransfer.SignatureTransferDetails' ;
195
+ ;
196
+
197
+
198
+
199
+
200
200
 
201
201
  export const PermitWitnessTransferFromInputComponents = [
202
202
  {
@@ -215,11 +215,11 @@ export const PermitWitnessTransferFromInputComponents = [
215
215
  { name: 'witness', type: 'bytes32' },
216
216
  { name: 'witnessTypeString', type: 'string' },
217
217
  { name: 'signature', type: 'bytes' },
218
- ] as const satisfies AbiParameter[];
219
- export type PermitWitnessTransferFromPayload = AbiParameterToPrimitiveType<{
220
- type: 'tuple';
221
- components: typeof PermitWitnessTransferFromInputComponents;
222
- }>;
218
+ ] ;
219
+ ;
220
+
221
+
222
+
223
223
 
224
224
  export const BatchPermitWitnessTransferFromInputComponents = [
225
225
  {
@@ -238,12 +238,12 @@ export const BatchPermitWitnessTransferFromInputComponents = [
238
238
  { name: 'witness', type: 'bytes32' },
239
239
  { name: 'witnessTypeString', type: 'string' },
240
240
  { name: 'signature', type: 'bytes' },
241
- ] as const satisfies AbiParameter[];
242
- export type BatchPermitWitnessTransferFromPayload =
243
- AbiParameterToPrimitiveType<{
244
- type: 'tuple';
245
- components: typeof BatchPermitWitnessTransferFromInputComponents;
246
- }>;
241
+ ] ;
242
+ ;
243
+
244
+
245
+
246
+
247
247
 
248
248
  export const PermitWitnessTransferFromFunctionABIType = {
249
249
  name: 'permitWitnessTransferFrom',
@@ -251,7 +251,7 @@ export const PermitWitnessTransferFromFunctionABIType = {
251
251
  outputs: [],
252
252
  stateMutability: 'nonpayable',
253
253
  type: 'function',
254
- } as const satisfies AbiFunction;
254
+ } ;
255
255
 
256
256
  export const BatchPermitWitnessTransferFunctionABIType = {
257
257
  name: 'permitWitnessTransferFrom',
@@ -259,4 +259,4 @@ export const BatchPermitWitnessTransferFunctionABIType = {
259
259
  outputs: [],
260
260
  stateMutability: 'nonpayable',
261
261
  type: 'function',
262
- } as const satisfies AbiFunction;
262
+ } ;
@@ -6,18 +6,18 @@
6
6
  * Copied from https://github.com/wevm/viem/blob/ea0b9d4c391567dd811acbfd889121bb9cb1c26c/src/utils/signature/hashTypedData.ts
7
7
  */
8
8
 
9
- type MessageTypeProperty = {
10
- name: string;
11
- type: string;
12
- };
9
+
10
+
11
+
12
+
13
13
 
14
14
  export function encodeType({
15
15
  primaryType,
16
16
  types,
17
- }: {
18
- primaryType: string;
19
- types: Record<string, readonly MessageTypeProperty[]>;
20
- }) {
17
+ }
18
+
19
+
20
+ ) {
21
21
  let result = '';
22
22
  const unsortedDeps = findTypeDependencies({ primaryType, types });
23
23
  unsortedDeps.delete(primaryType);
@@ -36,14 +36,14 @@ function findTypeDependencies(
36
36
  {
37
37
  primaryType: primaryType_,
38
38
  types,
39
- }: {
40
- primaryType: string;
41
- types: Record<string, readonly MessageTypeProperty[]>;
42
- },
43
- results: Set<string> = new Set(),
44
- ): Set<string> {
39
+ }
40
+
41
+
42
+ ,
43
+ results = new Set(),
44
+ ) {
45
45
  const match = primaryType_.match(/^\w*/u);
46
- const primaryType = match?.[0] as string;
46
+ const primaryType = match?.[0] ;
47
47
  if (results.has(primaryType) || types[primaryType] === undefined) {
48
48
  return results;
49
49
  }