@meshconnect/uwc-types 0.32.0 → 0.33.0-snapshot.dadc9f7

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.
@@ -94,6 +94,18 @@ export interface ConnectorConnectOptions {
94
94
  */
95
95
  silentOnly?: boolean;
96
96
  }
97
+ /**
98
+ * Session state a connector's send is held to.
99
+ */
100
+ export interface ConnectorSendOptions {
101
+ /**
102
+ * The network the session is on. The injected connector refuses an EVM
103
+ * send (EIP-1193 4901) when the wallet is on another chain, rather than let
104
+ * the wallet sign it there. The session's network, not the connector's own
105
+ * state: a superseded connect can still write the latter, never the former.
106
+ */
107
+ networkId?: NetworkId | undefined;
108
+ }
97
109
  /**
98
110
  * Common interface for all wallet connectors
99
111
  */
@@ -174,9 +186,10 @@ export interface Connector {
174
186
  * Send a transaction with the connected wallet
175
187
  * @param request The transaction request parameters
176
188
  * @param provider The wallet provider (required for injected connector)
189
+ * @param options What the session holds; see {@link ConnectorSendOptions}
177
190
  * @returns A promise that resolves to the transaction result
178
191
  */
179
- sendTransaction?(request: TransactionRequest, provider?: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider | WalletConnectProvider | TonConnectWalletProvider): Promise<TransactionResult>;
192
+ sendTransaction?(request: TransactionRequest, provider?: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider | WalletConnectProvider | TonConnectWalletProvider, options?: ConnectorSendOptions): Promise<TransactionResult>;
180
193
  getWalletCapabilities?(from: string, networks: Network[]): Promise<Record<string, EVMCapabilities>>;
181
194
  /**
182
195
  * Sign a Solana tx without broadcasting — raw bytes in/out (no @solana/web3.js
@@ -1 +1 @@
1
- {"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../src/connector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;A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/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export * from './signature';
13
13
  export * from './transactions';
14
14
  export * from './errors';
15
15
  export * from './solana-message';
16
+ export * from './solana-transaction';
16
17
  export * from './observability';
17
18
  export * from './bounded-dedup';
18
19
  export * from './safe-error-message';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,UAAU,CAAA;AACxB,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,sBAAsB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,UAAU,CAAA;AACxB,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,sBAAsB,CAAA"}
package/dist/index.js CHANGED
@@ -13,6 +13,7 @@ export * from './signature';
13
13
  export * from './transactions';
14
14
  export * from './errors';
15
15
  export * from './solana-message';
16
+ export * from './solana-transaction';
16
17
  export * from './observability';
17
18
  export * from './bounded-dedup';
18
19
  export * from './safe-error-message';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,UAAU,CAAA;AACxB,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,sBAAsB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,UAAU,CAAA;AACxB,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,sBAAsB,CAAA"}
@@ -34,6 +34,17 @@ export interface EIP712TypedData {
34
34
  * @see https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator
35
35
  */
36
36
  export declare function withEIP712Domain(typedData: EIP712TypedData): EIP712TypedData;
37
+ /**
38
+ * Wire form of a `personal_sign` message. The JSON-RPC spec types the param as
39
+ * hex `DATA`, and strict wallets hex-decode whatever arrives: Coinbase Wallet's
40
+ * in-app browser rejects raw text with `-32603` "Invalid message", and wallets
41
+ * that decode it anyway sign different bytes than the text the caller verifies.
42
+ * MetaMask and Trust Wallet hex-decode before hashing, so the EIP-191 digest is
43
+ * unchanged for them. Even-length `0x…` input passes through so a caller that
44
+ * pre-encoded is not double-encoded; odd-length `0x…` is not valid hex bytes,
45
+ * so it is UTF-8 encoded like any other text.
46
+ */
47
+ export declare function toPersonalSignData(message: string): string;
37
48
  /**
38
49
  * Standard signature format for most blockchains (EVM, Solana, etc.)
39
50
  */
@@ -1 +1 @@
1
- {"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../src/signature.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,iCAAiC,EAClC,MAAM,aAAa,CAAA;AAEpB;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE;QACN,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,iBAAiB,CAAC,EAAE,MAAM,CAAA;QAC1B,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,CAAA;IACD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAA;IAC5D,WAAW,EAAE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EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAErC;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,KAAK,CAAA;IACX,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,kBAAkB,CAAA;CAC5B;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,iBAAiB,GAAG,aAAa,GAAG,YAAY,CAAA;AAE5E;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,aAAa,CAAA;IACxB,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;OAKG;IACH,WAAW,CACT,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,yBAAyB,GAAG,iCAAiC,GACtE,OAAO,CAAC,eAAe,CAAC,CAAA;CAC5B"}
package/dist/signature.js CHANGED
@@ -37,4 +37,20 @@ export function withEIP712Domain(typedData) {
37
37
  }
38
38
  };
39
39
  }
40
+ /**
41
+ * Wire form of a `personal_sign` message. The JSON-RPC spec types the param as
42
+ * hex `DATA`, and strict wallets hex-decode whatever arrives: Coinbase Wallet's
43
+ * in-app browser rejects raw text with `-32603` "Invalid message", and wallets
44
+ * that decode it anyway sign different bytes than the text the caller verifies.
45
+ * MetaMask and Trust Wallet hex-decode before hashing, so the EIP-191 digest is
46
+ * unchanged for them. Even-length `0x…` input passes through so a caller that
47
+ * pre-encoded is not double-encoded; odd-length `0x…` is not valid hex bytes,
48
+ * so it is UTF-8 encoded like any other text.
49
+ */
50
+ export function toPersonalSignData(message) {
51
+ if (/^0x(?:[0-9a-fA-F]{2})*$/.test(message))
52
+ return message;
53
+ const bytes = new TextEncoder().encode(message);
54
+ return `0x${Array.from(bytes, b => b.toString(16).padStart(2, '0')).join('')}`;
55
+ }
40
56
  //# sourceMappingURL=signature.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signature.js","sourceRoot":"","sources":["../src/signature.ts"],"names":[],"mappings":"AAsBA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAA0B;IACzD,IAAI,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,cAAc,CAAC;QAAE,OAAO,SAAS,CAAA;IAEpE,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;IAC5B,MAAM,YAAY,GAA0C,EAAE,CAAA;IAE9D,2EAA2E;IAC3E,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS;QAC3B,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;IACrD,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS;QAC9B,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;IACxD,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS;QAC9B,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;IACzD,IAAI,MAAM,CAAC,iBAAiB,KAAK,SAAS;QACxC,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;IACnE,IAAI,MAAM,CAAC,IAAI,KAAK,S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E,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;IAEtD,OAAO;QACL,GAAG,SAAS;QACZ,KAAK,EAAE;YACL,YAAY,EAAE,YAAY;YAC1B,GAAG,SAAS,CAAC,KAAK;SACnB;KACF,CAAA;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAChD,IAAI,yBAAyB,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAA;IAC3D,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAC/C,OAAO,KAAK,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAA;AAChF,CAAC"}
@@ -0,0 +1,40 @@
1
+ import type { SolanaAddressLookupTable } from './transactions';
2
+ /**
3
+ * Solana transaction helpers shared by the injected and WalletConnect
4
+ * connectors. No @solana/web3.js: callers pass in what needs it.
5
+ */
6
+ /**
7
+ * Solana's maximum serialized transaction size (web3.js `PACKET_DATA_SIZE`).
8
+ * Signature slots are already allocated in an unsigned transaction, so signing
9
+ * does not change its length.
10
+ */
11
+ export declare const SOLANA_TRANSACTION_SIZE_LIMIT = 1232;
12
+ /**
13
+ * Serialize a transaction, refusing one the network would reject for its size
14
+ * before any wallet is asked to sign it. web3.js only throws (`encoding
15
+ * overruns Uint8Array`) when the message alone is over the limit; a transaction
16
+ * a few bytes over still serializes and would reach the wallet.
17
+ */
18
+ export declare function serializeWithinSizeLimit(transaction: {
19
+ serialize(): Uint8Array;
20
+ }): Uint8Array;
21
+ /** A lookup table in web3.js's `AddressLookupTableAccount` constructor shape. */
22
+ export interface ParsedLookupTable<Key> {
23
+ key: Key;
24
+ state: {
25
+ deactivationSlot: bigint;
26
+ lastExtendedSlot: number;
27
+ lastExtendedSlotStartIndex: number;
28
+ addresses: Key[];
29
+ authority?: Key;
30
+ };
31
+ }
32
+ /**
33
+ * Rebuild the caller's address lookup tables, addresses included, so
34
+ * `compileToV0Message` can swap inlined 32-byte account keys for one-byte
35
+ * table indexes. Without the addresses every account is inlined and a large
36
+ * route (a multi-hop swap) goes over the size limit. Invalid data throws an
37
+ * error naming the table and field.
38
+ */
39
+ export declare function parseLookupTables<Key>(states: SolanaAddressLookupTable[], toKey: (value: string) => Key): ParsedLookupTable<Key>[];
40
+ //# sourceMappingURL=solana-transaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solana-transaction.d.ts","sourceRoot":"","sources":["../src/solana-transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAA;AAE9D;;;GAGG;AAEH;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,OAAO,CAAA;AAQjD;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE;IACpD,SAAS,IAAI,UAAU,CAAA;CACxB,GAAG,UAAU,CAiBb;AAED,iFAAiF;AACjF,MAAM,WAAW,iBAAiB,CAAC,GAAG;IACpC,GAAG,EAAE,GAAG,CAAA;IACR,KAAK,EAAE;QACL,gBAAgB,EAAE,MAAM,CAAA;QACxB,gBAAgB,EAAE,MAAM,CAAA;QACxB,0BAA0B,EAAE,MAAM,CAAA;QAClC,SAAS,EAAE,GAAG,EAAE,CAAA;QAChB,SAAS,CAAC,EAAE,GAAG,CAAA;KAChB,CAAA;CACF;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EACnC,MAAM,EAAE,wBAAwB,EAAE,EAClC,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,GAAG,GAC5B,iBAAiB,CAAC,GAAG,CAAC,EAAE,CA2B1B"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Solana transaction helpers shared by the injected and WalletConnect
3
+ * connectors. No @solana/web3.js: callers pass in what needs it.
4
+ */
5
+ /**
6
+ * Solana's maximum serialized transaction size (web3.js `PACKET_DATA_SIZE`).
7
+ * Signature slots are already allocated in an unsigned transaction, so signing
8
+ * does not change its length.
9
+ */
10
+ export const SOLANA_TRANSACTION_SIZE_LIMIT = 1232;
11
+ const tooLarge = (size) => new Error(`Solana transaction is too large to send: ${size}, over the ${SOLANA_TRANSACTION_SIZE_LIMIT}-byte limit. ` +
12
+ 'A large route needs its address lookup tables passed in `states`.');
13
+ /**
14
+ * Serialize a transaction, refusing one the network would reject for its size
15
+ * before any wallet is asked to sign it. web3.js only throws (`encoding
16
+ * overruns Uint8Array`) when the message alone is over the limit; a transaction
17
+ * a few bytes over still serializes and would reach the wallet.
18
+ */
19
+ export function serializeWithinSizeLimit(transaction) {
20
+ let bytes;
21
+ try {
22
+ bytes = transaction.serialize();
23
+ }
24
+ catch (error) {
25
+ if (error instanceof RangeError &&
26
+ /encoding overruns/.test(error.message)) {
27
+ throw tooLarge('the message alone does not fit');
28
+ }
29
+ throw error;
30
+ }
31
+ if (bytes.length > SOLANA_TRANSACTION_SIZE_LIMIT) {
32
+ throw tooLarge(`${bytes.length} bytes`);
33
+ }
34
+ return bytes;
35
+ }
36
+ /**
37
+ * Rebuild the caller's address lookup tables, addresses included, so
38
+ * `compileToV0Message` can swap inlined 32-byte account keys for one-byte
39
+ * table indexes. Without the addresses every account is inlined and a large
40
+ * route (a multi-hop swap) goes over the size limit. Invalid data throws an
41
+ * error naming the table and field.
42
+ */
43
+ export function parseLookupTables(states, toKey) {
44
+ return states.map((state, tableIndex) => {
45
+ const label = `address lookup table ${tableIndex}`;
46
+ const key = (value, field) => {
47
+ try {
48
+ return toKey(value);
49
+ }
50
+ catch {
51
+ throw new Error(`Invalid ${label} ${field}: ${String(value)}`);
52
+ }
53
+ };
54
+ if (!Array.isArray(state.addresses)) {
55
+ throw new Error(`Invalid ${label}: addresses must be an array`);
56
+ }
57
+ return {
58
+ key: key(state.key, 'key'),
59
+ state: {
60
+ deactivationSlot: toSlot(state.deactivationSlot, label),
61
+ lastExtendedSlot: state.lastExtendedSlot,
62
+ lastExtendedSlotStartIndex: state.lastExtendedStartIndex,
63
+ addresses: state.addresses.map((address, index) => key(address, `address ${index}`)),
64
+ ...(state.authority && { authority: key(state.authority, 'authority') })
65
+ }
66
+ };
67
+ });
68
+ }
69
+ // The slot crosses JSON as a number or string even though the type says
70
+ // bigint, so normalise it to the bigint web3.js expects. Only the string form
71
+ // keeps u64::MAX exact: as a JSON number it arrives as 2^64.
72
+ const toSlot = (value, label) => {
73
+ try {
74
+ return BigInt(value);
75
+ }
76
+ catch {
77
+ throw new Error(`Invalid ${label} deactivation slot: ${String(value)}`);
78
+ }
79
+ };
80
+ //# sourceMappingURL=solana-transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solana-transaction.js","sourceRoot":"","sources":["../src/solana-transaction.ts"],"names":[],"mappings":"AAEA;;;GAGG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,IAAI,CAAA;AAEjD,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAS,EAAE,CACvC,IAAI,KAAK,CACP,4CAA4C,IAAI,cAAc,6BAA6B,eAAe;IACxG,mEAAmE,CACtE,CAAA;AAEH;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,WAExC;IACC,IAAI,KAAiB,CAAA;IACrB,IAAI,CAAC;QACH,KAAK,GAAG,WAAW,CAAC,SAAS,EAAE,CAAA;IACjC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IACE,KAAK,YAAY,UAAU;YAC3B,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EACvC,CAAC;YACD,MAAM,QAAQ,CAAC,gCAAgC,CAAC,CAAA;QAClD,CAAC;QACD,MAAM,KAAK,CAAA;IACb,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,G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AG,CAAC,KAAK,CAAC,SAAS,EAAE,WAAW,CAAC,EAAE,CAAC;aACzE;SACF,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,wEAAwE;AACxE,8EAA8E;AAC9E,6DAA6D;AAC7D,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,KAAa,EAAU,EAAE;IACtD,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IACtB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,WAAW,KAAK,uBAAuB,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IACzE,CAAC;AACH,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshconnect/uwc-types",
3
- "version": "0.32.0",
3
+ "version": "0.33.0-snapshot.dadc9f7",
4
4
  "description": "TypeScript types for Universal Wallet Connector",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/connector.ts CHANGED
@@ -110,6 +110,19 @@ export interface ConnectorConnectOptions {
110
110
  silentOnly?: boolean
111
111
  }
112
112
 
113
+ /**
114
+ * Session state a connector's send is held to.
115
+ */
116
+ export interface ConnectorSendOptions {
117
+ /**
118
+ * The network the session is on. The injected connector refuses an EVM
119
+ * send (EIP-1193 4901) when the wallet is on another chain, rather than let
120
+ * the wallet sign it there. The session's network, not the connector's own
121
+ * state: a superseded connect can still write the latter, never the former.
122
+ */
123
+ networkId?: NetworkId | undefined
124
+ }
125
+
113
126
  /**
114
127
  * Common interface for all wallet connectors
115
128
  */
@@ -240,6 +253,7 @@ export interface Connector {
240
253
  * Send a transaction with the connected wallet
241
254
  * @param request The transaction request parameters
242
255
  * @param provider The wallet provider (required for injected connector)
256
+ * @param options What the session holds; see {@link ConnectorSendOptions}
243
257
  * @returns A promise that resolves to the transaction result
244
258
  */
245
259
  sendTransaction?(
@@ -248,7 +262,8 @@ export interface Connector {
248
262
  | ExtensionInjectedProvider
249
263
  | IntegratedBrowserInjectedProvider
250
264
  | WalletConnectProvider
251
- | TonConnectWalletProvider
265
+ | TonConnectWalletProvider,
266
+ options?: ConnectorSendOptions
252
267
  ): Promise<TransactionResult>
253
268
 
254
269
  getWalletCapabilities?(
package/src/index.ts CHANGED
@@ -13,6 +13,7 @@ export * from './signature'
13
13
  export * from './transactions'
14
14
  export * from './errors'
15
15
  export * from './solana-message'
16
+ export * from './solana-transaction'
16
17
  export * from './observability'
17
18
  export * from './bounded-dedup'
18
19
  export * from './safe-error-message'
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect } from 'vitest'
2
- import { withEIP712Domain } from './signature'
2
+ import { toPersonalSignData, withEIP712Domain } from './signature'
3
3
  import type { EIP712TypedData } from './signature'
4
4
 
5
5
  const baseTypes = {
@@ -195,3 +195,40 @@ describe('withEIP712Domain', () => {
195
195
  expect(keys[0]).toBe('EIP712Domain')
196
196
  })
197
197
  })
198
+
199
+ const hexToUtf8 = (hex: string) =>
200
+ new TextDecoder().decode(
201
+ Uint8Array.from(hex.slice(2).match(/../g) ?? [], byte =>
202
+ Number.parseInt(byte, 16)
203
+ )
204
+ )
205
+
206
+ describe('toPersonalSignData', () => {
207
+ it('hex-encodes ASCII text', () => {
208
+ expect(toPersonalSignData('Hello')).toBe('0x48656c6c6f')
209
+ })
210
+
211
+ it('hex-encodes multi-byte UTF-8 and newlines so decoding returns the exact text', () => {
212
+ const message = 'Verify your wallet\nfor Revolut ✨ 日本'
213
+
214
+ const wire = toPersonalSignData(message)
215
+
216
+ expect(wire).toMatch(/^0x(?:[0-9a-f]{2})+$/)
217
+ expect(hexToUtf8(wire)).toBe(message)
218
+ })
219
+
220
+ it('passes through even-length 0x-hex in either case', () => {
221
+ expect(toPersonalSignData('0xdeadbeef')).toBe('0xdeadbeef')
222
+ expect(toPersonalSignData('0xDEADBEEF')).toBe('0xDEADBEEF')
223
+ })
224
+
225
+ it('UTF-8 encodes an odd-length 0x string instead of treating it as hex bytes', () => {
226
+ expect(toPersonalSignData('0xabc')).toBe('0x3078616263')
227
+ })
228
+
229
+ it('UTF-8 encodes a 0x string with non-hex characters', () => {
230
+ const message = '0xnot-hex'
231
+
232
+ expect(hexToUtf8(toPersonalSignData(message))).toBe(message)
233
+ })
234
+ })
package/src/signature.ts CHANGED
@@ -62,6 +62,22 @@ export function withEIP712Domain(typedData: EIP712TypedData): EIP712TypedData {
62
62
  }
63
63
  }
64
64
 
65
+ /**
66
+ * Wire form of a `personal_sign` message. The JSON-RPC spec types the param as
67
+ * hex `DATA`, and strict wallets hex-decode whatever arrives: Coinbase Wallet's
68
+ * in-app browser rejects raw text with `-32603` "Invalid message", and wallets
69
+ * that decode it anyway sign different bytes than the text the caller verifies.
70
+ * MetaMask and Trust Wallet hex-decode before hashing, so the EIP-191 digest is
71
+ * unchanged for them. Even-length `0x…` input passes through so a caller that
72
+ * pre-encoded is not double-encoded; odd-length `0x…` is not valid hex bytes,
73
+ * so it is UTF-8 encoded like any other text.
74
+ */
75
+ export function toPersonalSignData(message: string): string {
76
+ if (/^0x(?:[0-9a-fA-F]{2})*$/.test(message)) return message
77
+ const bytes = new TextEncoder().encode(message)
78
+ return `0x${Array.from(bytes, b => b.toString(16).padStart(2, '0')).join('')}`
79
+ }
80
+
65
81
  /**
66
82
  * Standard signature format for most blockchains (EVM, Solana, etc.)
67
83
  */
@@ -0,0 +1,166 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import type { SolanaAddressLookupTable } from './transactions'
3
+ import {
4
+ SOLANA_TRANSACTION_SIZE_LIMIT,
5
+ parseLookupTables,
6
+ serializeWithinSizeLimit
7
+ } from './solana-transaction'
8
+
9
+ const ACTIVE = BigInt('18446744073709551615')
10
+
11
+ // Stands in for `new PublicKey(value)`: tags valid keys, throws like it does.
12
+ const toKey = (value: string) => {
13
+ if (!/^key-\d+$/.test(value)) throw new Error('Invalid public key input')
14
+ return { key: value }
15
+ }
16
+
17
+ const table = (
18
+ over: Partial<SolanaAddressLookupTable> = {}
19
+ ): SolanaAddressLookupTable => ({
20
+ key: 'key-0',
21
+ addresses: ['key-1', 'key-2'],
22
+ deactivationSlot: ACTIVE,
23
+ lastExtendedSlot: 280_000_000,
24
+ lastExtendedStartIndex: 3,
25
+ ...over
26
+ })
27
+
28
+ describe('parseLookupTables', () => {
29
+ it('keeps every address, in order, in web3.js AddressLookupTableAccount shape', () => {
30
+ expect(parseLookupTables([table()], toKey)).toEqual([
31
+ {
32
+ key: { key: 'key-0' },
33
+ state: {
34
+ deactivationSlot: ACTIVE,
35
+ lastExtendedSlot: 280_000_000,
36
+ lastExtendedSlotStartIndex: 3,
37
+ addresses: [{ key: 'key-1' }, { key: 'key-2' }]
38
+ }
39
+ }
40
+ ])
41
+ })
42
+
43
+ it('parses several tables', () => {
44
+ const parsed = parseLookupTables(
45
+ [table(), table({ key: 'key-9', addresses: ['key-8'] })],
46
+ toKey
47
+ )
48
+
49
+ expect(parsed.map(t => t.key.key)).toEqual(['key-0', 'key-9'])
50
+ expect(parsed[1]!.state.addresses).toEqual([{ key: 'key-8' }])
51
+ })
52
+
53
+ it('returns no tables for no states', () => {
54
+ expect(parseLookupTables([], toKey)).toEqual([])
55
+ })
56
+
57
+ it.each([
58
+ ['a bigint', ACTIVE, ACTIVE],
59
+ ['a number', 280_000_000, 280_000_000n],
60
+ ['a string (keeps u64::MAX exact)', '18446744073709551615', ACTIVE],
61
+ // JSON.parse turns u64::MAX into 2^64. web3.js does not read the slot
62
+ // when compiling, so the table still applies.
63
+ [
64
+ 'a JSON number (u64::MAX rounds up)',
65
+ JSON.parse('18446744073709551615'),
66
+ 2n ** 64n
67
+ ]
68
+ ])('normalises a deactivation slot sent as %s', (_, slot, expected) => {
69
+ const [parsed] = parseLookupTables(
70
+ [table({ deactivationSlot: slot as unknown as bigint })],
71
+ toKey
72
+ )
73
+
74
+ expect(parsed!.state.deactivationSlot).toBe(expected)
75
+ })
76
+
77
+ it('keeps a valid authority', () => {
78
+ const [parsed] = parseLookupTables([table({ authority: 'key-7' })], toKey)
79
+
80
+ expect(parsed!.state.authority).toEqual({ key: 'key-7' })
81
+ })
82
+
83
+ it.each([
84
+ ['omitted', undefined],
85
+ ['empty', '']
86
+ ])('leaves out an %s authority', (_, authority) => {
87
+ const [parsed] = parseLookupTables([table({ authority })], toKey)
88
+
89
+ expect(parsed!.state).not.toHaveProperty('authority')
90
+ })
91
+
92
+ it.each([
93
+ [
94
+ 'a bad table key',
95
+ [table(), table({ key: 'nope' })],
96
+ 'Invalid address lookup table 1 key: nope'
97
+ ],
98
+ [
99
+ 'a bad address, naming its index',
100
+ [table({ addresses: ['key-1', 'bad'] })],
101
+ 'Invalid address lookup table 0 address 1: bad'
102
+ ],
103
+ [
104
+ 'a bad authority',
105
+ [table({ authority: '0x123' })],
106
+ 'Invalid address lookup table 0 authority: 0x123'
107
+ ],
108
+ [
109
+ 'addresses that are not an array',
110
+ [table({ addresses: 'nope' as unknown as string[] })],
111
+ 'Invalid address lookup table 0: addresses must be an array'
112
+ ],
113
+ [
114
+ 'a deactivation slot that is not an integer',
115
+ [table({ deactivationSlot: 'soon' as unknown as bigint })],
116
+ 'Invalid address lookup table 0 deactivation slot: soon'
117
+ ]
118
+ ])('throws a clear error for %s', (_, states, message) => {
119
+ expect(() => parseLookupTables(states, toKey)).toThrow(message)
120
+ })
121
+ })
122
+
123
+ describe('serializeWithinSizeLimit', () => {
124
+ const ofLength = (length: number) => ({
125
+ serialize: () => new Uint8Array(length)
126
+ })
127
+
128
+ it('allows up to the limit', () => {
129
+ expect(SOLANA_TRANSACTION_SIZE_LIMIT).toBe(1232)
130
+ expect(serializeWithinSizeLimit(ofLength(1232))).toHaveLength(1232)
131
+ })
132
+
133
+ it('refuses anything over the limit, saying how big it is', () => {
134
+ expect(() => serializeWithinSizeLimit(ofLength(1233))).toThrow(
135
+ 'Solana transaction is too large to send: 1233 bytes, over the 1232-byte limit. A large route needs its address lookup tables passed in `states`.'
136
+ )
137
+ })
138
+
139
+ it("turns web3.js's encoding overrun into the same clear error", () => {
140
+ const overrun = {
141
+ serialize: () => {
142
+ throw new RangeError('encoding overruns Uint8Array')
143
+ }
144
+ }
145
+
146
+ expect(() => serializeWithinSizeLimit(overrun)).toThrow(
147
+ 'Solana transaction is too large to send: the message alone does not fit, over the 1232-byte limit.'
148
+ )
149
+ })
150
+
151
+ it.each([
152
+ ['an unrelated error', new Error('boom')],
153
+ [
154
+ 'a RangeError about something else',
155
+ new RangeError('offset is out of range')
156
+ ]
157
+ ])('rethrows %s unchanged', (_, error) => {
158
+ const failing = {
159
+ serialize: () => {
160
+ throw error
161
+ }
162
+ }
163
+
164
+ expect(() => serializeWithinSizeLimit(failing)).toThrow(error)
165
+ })
166
+ })
@@ -0,0 +1,108 @@
1
+ import type { SolanaAddressLookupTable } from './transactions'
2
+
3
+ /**
4
+ * Solana transaction helpers shared by the injected and WalletConnect
5
+ * connectors. No @solana/web3.js: callers pass in what needs it.
6
+ */
7
+
8
+ /**
9
+ * Solana's maximum serialized transaction size (web3.js `PACKET_DATA_SIZE`).
10
+ * Signature slots are already allocated in an unsigned transaction, so signing
11
+ * does not change its length.
12
+ */
13
+ export const SOLANA_TRANSACTION_SIZE_LIMIT = 1232
14
+
15
+ const tooLarge = (size: string): Error =>
16
+ new Error(
17
+ `Solana transaction is too large to send: ${size}, over the ${SOLANA_TRANSACTION_SIZE_LIMIT}-byte limit. ` +
18
+ 'A large route needs its address lookup tables passed in `states`.'
19
+ )
20
+
21
+ /**
22
+ * Serialize a transaction, refusing one the network would reject for its size
23
+ * before any wallet is asked to sign it. web3.js only throws (`encoding
24
+ * overruns Uint8Array`) when the message alone is over the limit; a transaction
25
+ * a few bytes over still serializes and would reach the wallet.
26
+ */
27
+ export function serializeWithinSizeLimit(transaction: {
28
+ serialize(): Uint8Array
29
+ }): Uint8Array {
30
+ let bytes: Uint8Array
31
+ try {
32
+ bytes = transaction.serialize()
33
+ } catch (error) {
34
+ if (
35
+ error instanceof RangeError &&
36
+ /encoding overruns/.test(error.message)
37
+ ) {
38
+ throw tooLarge('the message alone does not fit')
39
+ }
40
+ throw error
41
+ }
42
+ if (bytes.length > SOLANA_TRANSACTION_SIZE_LIMIT) {
43
+ throw tooLarge(`${bytes.length} bytes`)
44
+ }
45
+ return bytes
46
+ }
47
+
48
+ /** A lookup table in web3.js's `AddressLookupTableAccount` constructor shape. */
49
+ export interface ParsedLookupTable<Key> {
50
+ key: Key
51
+ state: {
52
+ deactivationSlot: bigint
53
+ lastExtendedSlot: number
54
+ lastExtendedSlotStartIndex: number
55
+ addresses: Key[]
56
+ authority?: Key
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Rebuild the caller's address lookup tables, addresses included, so
62
+ * `compileToV0Message` can swap inlined 32-byte account keys for one-byte
63
+ * table indexes. Without the addresses every account is inlined and a large
64
+ * route (a multi-hop swap) goes over the size limit. Invalid data throws an
65
+ * error naming the table and field.
66
+ */
67
+ export function parseLookupTables<Key>(
68
+ states: SolanaAddressLookupTable[],
69
+ toKey: (value: string) => Key
70
+ ): ParsedLookupTable<Key>[] {
71
+ return states.map((state, tableIndex) => {
72
+ const label = `address lookup table ${tableIndex}`
73
+ const key = (value: string, field: string): Key => {
74
+ try {
75
+ return toKey(value)
76
+ } catch {
77
+ throw new Error(`Invalid ${label} ${field}: ${String(value)}`)
78
+ }
79
+ }
80
+ if (!Array.isArray(state.addresses)) {
81
+ throw new Error(`Invalid ${label}: addresses must be an array`)
82
+ }
83
+
84
+ return {
85
+ key: key(state.key, 'key'),
86
+ state: {
87
+ deactivationSlot: toSlot(state.deactivationSlot, label),
88
+ lastExtendedSlot: state.lastExtendedSlot,
89
+ lastExtendedSlotStartIndex: state.lastExtendedStartIndex,
90
+ addresses: state.addresses.map((address, index) =>
91
+ key(address, `address ${index}`)
92
+ ),
93
+ ...(state.authority && { authority: key(state.authority, 'authority') })
94
+ }
95
+ }
96
+ })
97
+ }
98
+
99
+ // The slot crosses JSON as a number or string even though the type says
100
+ // bigint, so normalise it to the bigint web3.js expects. Only the string form
101
+ // keeps u64::MAX exact: as a JSON number it arrives as 2^64.
102
+ const toSlot = (value: bigint, label: string): bigint => {
103
+ try {
104
+ return BigInt(value)
105
+ } catch {
106
+ throw new Error(`Invalid ${label} deactivation slot: ${String(value)}`)
107
+ }
108
+ }