@agoric/orchestration 0.1.1-dev-d57b08e.0.d57b08e → 0.1.1-dev-2ae3f1f.0.2ae3f1f

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.
Files changed (34) hide show
  1. package/package.json +16 -16
  2. package/src/stubs/{viem-abi.d.ts → viem-typedData.ts} +9 -4
  3. package/src/utils/abitype.d.ts +6 -0
  4. package/src/utils/abitype.d.ts.map +1 -0
  5. package/src/utils/abitype.ts +13 -0
  6. package/src/utils/permit2/signatureTransfer.d.ts +208 -0
  7. package/src/utils/permit2/signatureTransfer.d.ts.map +1 -0
  8. package/src/utils/permit2/signatureTransfer.ts +240 -0
  9. package/src/utils/permit2/signatureTransferHelpers.d.ts +21 -0
  10. package/src/utils/permit2/signatureTransferHelpers.d.ts.map +1 -0
  11. package/src/utils/permit2/signatureTransferHelpers.ts +139 -0
  12. package/src/utils/permit2.d.ts +11 -0
  13. package/src/utils/permit2.d.ts.map +1 -0
  14. package/src/utils/permit2.ts +11 -0
  15. package/src/utils/viem-utils/hashTypedData.d.ts +17 -0
  16. package/src/utils/viem-utils/hashTypedData.d.ts.map +1 -0
  17. package/src/utils/viem-utils/hashTypedData.ts +57 -0
  18. package/src/utils/viem-utils/types.d.ts +6 -0
  19. package/src/utils/viem-utils/types.d.ts.map +1 -0
  20. package/src/utils/viem-utils/types.ts +18 -0
  21. package/src/utils/viem.d.ts +11 -0
  22. package/src/utils/viem.d.ts.map +1 -0
  23. package/src/utils/viem.ts +11 -0
  24. package/src/vendor/viem/{_esm-YOAV66U4.js → _esm-OKAICHVC.js} +2 -2
  25. package/src/vendor/viem/{ccip-AAQDZF3N.js → ccip-34BSSMV5.js} +1 -2
  26. package/src/vendor/viem/{chunk-4EF4K2MH.js → chunk-GCI53Z2G.js} +35 -1
  27. package/src/vendor/viem/chunk-OFIEVWYB.js +326 -0
  28. package/src/vendor/viem/viem-abi.js +2 -2
  29. package/src/vendor/viem/viem-typedData.d.ts +19 -0
  30. package/src/vendor/viem/viem-typedData.js +56 -0
  31. package/tsup.config.ts +13 -2
  32. package/src/stubs/viem-abi.d.ts.map +0 -1
  33. package/src/vendor/viem/chunk-XN4LUOIH.js +0 -253
  34. package/src/vendor/viem/secp256k1-WHBDSQB2.js +0 -1914
@@ -0,0 +1,139 @@
1
+ /**
2
+ * @file Helpers for working with permit2 signature transfer witness types
3
+ *
4
+ * This is original code that was adapted for permit2-sdk, unlike @see ./permit2SignatureTransfer.ts
5
+ */
6
+
7
+ import type { TypedData } from 'viem';
8
+ import type { TypedDataParameter } from '../abitype.ts';
9
+ import {
10
+ PermitBatchTransferFromTypeParams,
11
+ permitBatchWitnessTransferFromTypes,
12
+ PermitTransferFromTypeParams,
13
+ permitWitnessTransferFromTypes,
14
+ } from './signatureTransfer.ts';
15
+
16
+ export const makeWitnessTypeStringExtractor = ({
17
+ encodeType,
18
+ }: {
19
+ encodeType: ({
20
+ primaryType,
21
+ types,
22
+ }: {
23
+ primaryType: string;
24
+ types: TypedData;
25
+ }) => string;
26
+ }) => {
27
+ const baseTypeStrings = Object.fromEntries(
28
+ Object.entries({
29
+ PermitBatchWitnessTransferFrom: permitBatchWitnessTransferFromTypes,
30
+ PermitWitnessTransferFrom: permitWitnessTransferFromTypes,
31
+ }).map(([typeName, typeFunc]) => {
32
+ const encoded = encodeType({
33
+ primaryType: typeName,
34
+ // @ts-expect-error undefined is not allowed in types but supported in implementation
35
+ types: typeFunc(undefined),
36
+ });
37
+
38
+ const prefix = encoded.substring(0, encoded.indexOf(')'));
39
+ return [typeName, `${prefix},`];
40
+ }),
41
+ );
42
+
43
+ return function getWitnessTypeString(types: TypedData) {
44
+ const matchingTypes = Object.keys(types).filter(
45
+ type => type in baseTypeStrings,
46
+ );
47
+
48
+ if (matchingTypes.length !== 1) {
49
+ throw new Error(
50
+ `TypedData must have exactly one of the following types: ${Object.keys(baseTypeStrings).join(', ')}`,
51
+ );
52
+ }
53
+
54
+ const primaryType = matchingTypes[0];
55
+ const encodedType = encodeType({
56
+ primaryType,
57
+ types,
58
+ });
59
+
60
+ const baseTypeString = baseTypeStrings[primaryType];
61
+ if (!encodedType.startsWith(baseTypeString)) {
62
+ throw new Error(
63
+ `TypedData has an invalid type string for ${primaryType}`,
64
+ );
65
+ }
66
+
67
+ return encodedType.substring(baseTypeString.length);
68
+ };
69
+ };
70
+
71
+ type MapUnion<U> = {
72
+ [K in U extends any ? keyof U : never]: U extends any
73
+ ? K extends keyof U
74
+ ? U[K]
75
+ : never
76
+ : never;
77
+ };
78
+
79
+ export const extractWitnessFieldFromTypes = <
80
+ T extends Readonly<TypedDataParameter>,
81
+ >(
82
+ types:
83
+ | {
84
+ PermitBatchWitnessTransferFrom: readonly [
85
+ ...typeof PermitBatchTransferFromTypeParams,
86
+ T,
87
+ ];
88
+ }
89
+ | {
90
+ PermitWitnessTransferFrom: readonly [
91
+ ...typeof PermitTransferFromTypeParams,
92
+ T,
93
+ ];
94
+ },
95
+ ): T => {
96
+ const baseTypes = {
97
+ PermitBatchWitnessTransferFrom: PermitBatchTransferFromTypeParams,
98
+ PermitWitnessTransferFrom: PermitTransferFromTypeParams,
99
+ };
100
+
101
+ const matchingTypes = Object.keys(types).filter(
102
+ type => type in baseTypes,
103
+ ) as (keyof typeof baseTypes)[];
104
+
105
+ if (matchingTypes.length !== 1) {
106
+ throw new Error(
107
+ `TypedData must have exactly one of the following types: ${Object.keys(baseTypes).join(', ')}`,
108
+ );
109
+ }
110
+
111
+ const primaryType = matchingTypes[0];
112
+ const candidateType = (types as MapUnion<typeof types>)[primaryType];
113
+ const referenceType = baseTypes[primaryType];
114
+ if (candidateType.length !== referenceType.length + 1) {
115
+ throw new Error(
116
+ `TypedData has an invalid number of fields for ${primaryType}`,
117
+ );
118
+ }
119
+
120
+ for (const [i, field] of referenceType.entries()) {
121
+ if (
122
+ candidateType[i].name !== field.name ||
123
+ candidateType[i].type !== field.type
124
+ ) {
125
+ throw new Error(
126
+ `TypedData has an invalid field at index ${i} for ${primaryType}`,
127
+ );
128
+ }
129
+ }
130
+
131
+ return candidateType[candidateType.length - 1] as T;
132
+ };
133
+
134
+ export const isPermit2MessageType = (type: string) => {
135
+ return (
136
+ type === 'PermitBatchWitnessTransferFrom' ||
137
+ type === 'PermitWitnessTransferFrom'
138
+ );
139
+ };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @file entry point for orchestration's permit2 utils
3
+ *
4
+ * This file should eventually become a `.js` file once we can strip types from
5
+ * `.ts` files and rewrite relative import specifiers in `.js` files.
6
+ *
7
+ * NPM consumers could use jsr.io to consume this in the meantime.
8
+ */
9
+ export * from './permit2/signatureTransfer.ts';
10
+ export * from './permit2/signatureTransferHelpers.ts';
11
+ //# sourceMappingURL=permit2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permit2.d.ts","sourceRoot":"","sources":["permit2.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uCAAuC,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @file entry point for orchestration's permit2 utils
3
+ *
4
+ * This file should eventually become a `.js` file once we can strip types from
5
+ * `.ts` files and rewrite relative import specifiers in `.js` files.
6
+ *
7
+ * NPM consumers could use jsr.io to consume this in the meantime.
8
+ */
9
+
10
+ export * from './permit2/signatureTransfer.ts';
11
+ export * from './permit2/signatureTransferHelpers.ts';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @file viem internal typedData utils exported for direct usage
3
+ *
4
+ * @license MIT
5
+ * Copyright (c) 2023-present weth, LLC
6
+ * Copied from https://github.com/wevm/viem/blob/ea0b9d4c391567dd811acbfd889121bb9cb1c26c/src/utils/signature/hashTypedData.ts
7
+ */
8
+ type MessageTypeProperty = {
9
+ name: string;
10
+ type: string;
11
+ };
12
+ export declare function encodeType({ primaryType, types, }: {
13
+ primaryType: string;
14
+ types: Record<string, readonly MessageTypeProperty[]>;
15
+ }): string;
16
+ export {};
17
+ //# sourceMappingURL=hashTypedData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashTypedData.d.ts","sourceRoot":"","sources":["hashTypedData.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,KAAK,mBAAmB,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,wBAAgB,UAAU,CAAC,EACzB,WAAW,EACX,KAAK,GACN,EAAE;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,mBAAmB,EAAE,CAAC,CAAC;CACvD,UAaA"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @file viem internal typedData utils exported for direct usage
3
+ *
4
+ * @license MIT
5
+ * Copyright (c) 2023-present weth, LLC
6
+ * Copied from https://github.com/wevm/viem/blob/ea0b9d4c391567dd811acbfd889121bb9cb1c26c/src/utils/signature/hashTypedData.ts
7
+ */
8
+
9
+ type MessageTypeProperty = {
10
+ name: string;
11
+ type: string;
12
+ };
13
+
14
+ export function encodeType({
15
+ primaryType,
16
+ types,
17
+ }: {
18
+ primaryType: string;
19
+ types: Record<string, readonly MessageTypeProperty[]>;
20
+ }) {
21
+ let result = '';
22
+ const unsortedDeps = findTypeDependencies({ primaryType, types });
23
+ unsortedDeps.delete(primaryType);
24
+
25
+ const deps = [primaryType, ...Array.from(unsortedDeps).sort()];
26
+ for (const type of deps) {
27
+ result += `${type}(${types[type]
28
+ .map(({ name, type: t }) => `${t} ${name}`)
29
+ .join(',')})`;
30
+ }
31
+
32
+ return result;
33
+ }
34
+
35
+ function findTypeDependencies(
36
+ {
37
+ primaryType: primaryType_,
38
+ types,
39
+ }: {
40
+ primaryType: string;
41
+ types: Record<string, readonly MessageTypeProperty[]>;
42
+ },
43
+ results: Set<string> = new Set(),
44
+ ): Set<string> {
45
+ const match = primaryType_.match(/^\w*/u);
46
+ const primaryType = match?.[0] as string;
47
+ if (results.has(primaryType) || types[primaryType] === undefined) {
48
+ return results;
49
+ }
50
+
51
+ results.add(primaryType);
52
+
53
+ for (const field of types[primaryType]) {
54
+ findTypeDependencies({ primaryType: field.type, types }, results);
55
+ }
56
+ return results;
57
+ }
@@ -0,0 +1,6 @@
1
+ import type { ByteArray, Hex, Signature, TypedData, TypedDataDefinition } from 'viem';
2
+ export type WithSignature<T> = T & {
3
+ signature: Hex | ByteArray | Signature;
4
+ };
5
+ export type SignedTypedDataDefinition<typedData extends TypedData | Record<string, unknown> = TypedData, primaryType extends keyof typedData | 'EIP712Domain' = keyof typedData, primaryTypes = typedData extends TypedData ? keyof typedData : string> = WithSignature<TypedDataDefinition<typedData, primaryType, primaryTypes>>;
6
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,GAAG,EACH,SAAS,EACT,SAAS,EACT,mBAAmB,EACpB,MAAM,MAAM,CAAC;AAEd,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG;IACjC,SAAS,EAAE,GAAG,GAAG,SAAS,GAAG,SAAS,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,yBAAyB,CACnC,SAAS,SAAS,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EACjE,WAAW,SAAS,MAAM,SAAS,GAAG,cAAc,GAAG,MAAM,SAAS,EAEtE,YAAY,GAAG,SAAS,SAAS,SAAS,GAAG,MAAM,SAAS,GAAG,MAAM,IACnE,aAAa,CAAC,mBAAmB,CAAC,SAAS,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type {
2
+ ByteArray,
3
+ Hex,
4
+ Signature,
5
+ TypedData,
6
+ TypedDataDefinition,
7
+ } from 'viem';
8
+
9
+ export type WithSignature<T> = T & {
10
+ signature: Hex | ByteArray | Signature;
11
+ };
12
+
13
+ export type SignedTypedDataDefinition<
14
+ typedData extends TypedData | Record<string, unknown> = TypedData,
15
+ primaryType extends keyof typedData | 'EIP712Domain' = keyof typedData,
16
+ ///
17
+ primaryTypes = typedData extends TypedData ? keyof typedData : string,
18
+ > = WithSignature<TypedDataDefinition<typedData, primaryType, primaryTypes>>;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @file entry point for some common viem utils
3
+ *
4
+ * This file should eventually become a `.js` file once we can strip types from
5
+ * `.ts` files and rewrite relative import specifiers in `.js` files.
6
+ *
7
+ * NPM consumers could use jsr.io to consume this in the meantime.
8
+ */
9
+ export * from './viem-utils/hashTypedData.ts';
10
+ export * from './viem-utils/types.ts';
11
+ //# sourceMappingURL=viem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viem.d.ts","sourceRoot":"","sources":["viem.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @file entry point for some common viem utils
3
+ *
4
+ * This file should eventually become a `.js` file once we can strip types from
5
+ * `.ts` files and rewrite relative import specifiers in `.js` files.
6
+ *
7
+ * NPM consumers could use jsr.io to consume this in the meantime.
8
+ */
9
+
10
+ export * from './viem-utils/hashTypedData.ts';
11
+ export * from './viem-utils/types.ts';
@@ -2660,7 +2660,7 @@ var require_buffer = __commonJS({
2660
2660
  function numberIsNaN(obj) {
2661
2661
  return obj !== obj;
2662
2662
  }
2663
- var hexSliceLookupTable = function() {
2663
+ var hexSliceLookupTable = (function() {
2664
2664
  const alphabet = "0123456789abcdef";
2665
2665
  const table = new Array(256);
2666
2666
  for (let i = 0; i < 16; ++i) {
@@ -2670,7 +2670,7 @@ var require_buffer = __commonJS({
2670
2670
  }
2671
2671
  }
2672
2672
  return table;
2673
- }();
2673
+ })();
2674
2674
  function defineBigIntMethod(fn) {
2675
2675
  return typeof BigInt === "undefined" ? BufferBigIntNotDefined : fn;
2676
2676
  }
@@ -3,8 +3,7 @@ import {
3
3
  offchainLookup,
4
4
  offchainLookupAbiItem,
5
5
  offchainLookupSignature
6
- } from "./chunk-4EF4K2MH.js";
7
- import "./chunk-XN4LUOIH.js";
6
+ } from "./chunk-GCI53Z2G.js";
8
7
  import "./chunk-4VNS5WPM.js";
9
8
  export {
10
9
  ccipRequest,
@@ -708,6 +708,9 @@ function parseAbi(signatures) {
708
708
  return abi;
709
709
  }
710
710
 
711
+ // ../../node_modules/ox/_esm/core/Hex.js
712
+ import { equalBytes } from "@noble/curves/abstract/utils";
713
+
711
714
  // ../../node_modules/ox/_esm/core/version.js
712
715
  var version2 = "0.1.1";
713
716
 
@@ -1480,6 +1483,13 @@ var AbiItemAmbiguityError = class extends BaseError3 {
1480
1483
  });
1481
1484
  }
1482
1485
  };
1486
+ var BytesSizeMismatchError = class extends BaseError3 {
1487
+ constructor({ expectedSize, givenSize }) {
1488
+ super(`Expected bytes${expectedSize}, got bytes${givenSize}.`, {
1489
+ name: "BytesSizeMismatchError"
1490
+ });
1491
+ }
1492
+ };
1483
1493
  var InvalidAbiEncodingTypeError = class extends BaseError3 {
1484
1494
  constructor(type, { docsPath: docsPath6 }) {
1485
1495
  super([
@@ -1969,6 +1979,11 @@ function checksumAddress(address_, chainId) {
1969
1979
  checksumAddressCache.set(`${address_}.${chainId}`, result);
1970
1980
  return result;
1971
1981
  }
1982
+ function getAddress(address, chainId) {
1983
+ if (!isAddress(address, { strict: false }))
1984
+ throw new InvalidAddressError({ address });
1985
+ return checksumAddress(address, chainId);
1986
+ }
1972
1987
 
1973
1988
  // ../../node_modules/viem/_esm/errors/cursor.js
1974
1989
  var NegativeOffsetError = class extends BaseError3 {
@@ -2214,6 +2229,7 @@ function concatHex(values) {
2214
2229
  }
2215
2230
 
2216
2231
  // ../../node_modules/viem/_esm/utils/regex.js
2232
+ var bytesRegex2 = /^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/;
2217
2233
  var integerRegex2 = /^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/;
2218
2234
 
2219
2235
  // ../../node_modules/viem/_esm/utils/abi/encodeAbiParameters.js
@@ -3698,7 +3714,7 @@ async function call(client, args) {
3698
3714
  return { data: response };
3699
3715
  } catch (err) {
3700
3716
  const data2 = getRevertErrorData(err);
3701
- const { offchainLookup: offchainLookup2, offchainLookupSignature: offchainLookupSignature2 } = await import("./ccip-AAQDZF3N.js");
3717
+ const { offchainLookup: offchainLookup2, offchainLookupSignature: offchainLookupSignature2 } = await import("./ccip-34BSSMV5.js");
3702
3718
  if (client.ccipRead !== false && data2?.slice(0, 10) === offchainLookupSignature2 && to)
3703
3719
  return { data: await offchainLookup2(client, { data: data2, to }) };
3704
3720
  if (deploylessCall && data2?.slice(0, 10) === "0x101bb98d")
@@ -4072,9 +4088,27 @@ async function ccipRequest({ data, sender, urls }) {
4072
4088
  }
4073
4089
 
4074
4090
  export {
4091
+ BaseError3 as BaseError,
4092
+ stringify,
4093
+ isHex,
4094
+ size2 as size,
4095
+ hexToBigInt,
4096
+ hexToNumber,
4097
+ toHex,
4098
+ numberToHex,
4099
+ BytesSizeMismatchError,
4100
+ keccak256,
4101
+ InvalidAddressError,
4102
+ isAddress,
4103
+ checksumAddress,
4104
+ getAddress,
4105
+ concat,
4106
+ bytesRegex2 as bytesRegex,
4107
+ integerRegex2 as integerRegex,
4075
4108
  encodeAbiParameters,
4076
4109
  decodeAbiParameters,
4077
4110
  encodeFunctionData,
4111
+ isAddressEqual,
4078
4112
  offchainLookupSignature,
4079
4113
  offchainLookupAbiItem,
4080
4114
  offchainLookup,