@wuwei-labs/srsly 2.0.0-beta.45 → 2.0.0-beta.46

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wuwei-labs/srsly",
3
- "version": "2.0.0-beta.45",
3
+ "version": "2.0.0-beta.46",
4
4
  "description": "",
5
5
  "source": "./src/index.ts",
6
6
  "sideEffects": false,
@@ -1,28 +1,101 @@
1
1
  "use strict";
2
2
  /**
3
- * Universal signer handling utilities for cross-library compatibility
3
+ * Universal signer handling utilities for @solana/kit compatibility
4
4
  *
5
- * This module provides utilities to handle different signer types across
6
- * @solana/kit, @solana/web3.js, and plain address strings in a unified way.
5
+ * This module provides utilities to handle different signer types in a unified way
6
+ * while ensuring compatibility with @solana/kit. Supports string addresses for
7
+ * browser usage and TransactionSigner objects for Node.js usage.
8
+ *
9
+ * Note: web3.js signers (Keypair, etc.) are explicitly not supported.
10
+ * Use address strings or @solana/kit TransactionSigner objects instead.
7
11
  */
8
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.InvalidSignerError = void 0;
14
+ exports.validateSigner = validateSigner;
9
15
  exports.createTransactionSigner = createTransactionSigner;
10
16
  exports.isSignerObject = isSignerObject;
11
17
  exports.isAddressString = isAddressString;
12
18
  const kit_1 = require("@solana/kit");
13
19
  /**
14
- * Creates TransactionSigner from UniversalSigner input for universal compatibility
20
+ * Error thrown when an invalid signer type is provided
21
+ */
22
+ class InvalidSignerError extends Error {
23
+ constructor(message) {
24
+ super(message);
25
+ this.name = 'InvalidSignerError';
26
+ }
27
+ }
28
+ exports.InvalidSignerError = InvalidSignerError;
29
+ /**
30
+ * Validates that a signer is compatible with @solana/kit
31
+ *
32
+ * @param signer - The signer to validate
33
+ * @throws {InvalidSignerError} If the signer is not compatible
34
+ */
35
+ function validateSigner(signer) {
36
+ if (typeof signer === 'string') {
37
+ // Validate that the string is a valid Solana address
38
+ try {
39
+ // Use @solana/kit's address() function to validate - it will throw if invalid
40
+ (0, kit_1.address)(signer);
41
+ return;
42
+ }
43
+ catch (error) {
44
+ throw new InvalidSignerError(`Invalid address string: "${signer}". ${error instanceof Error ? error.message : 'Unknown validation error'}\n\n` +
45
+ 'Expected a valid base58-encoded Solana address (32-44 characters).\n' +
46
+ 'Examples:\n' +
47
+ ' - "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"\n' +
48
+ ' - "So11111111111111111111111111111111111111112"');
49
+ }
50
+ }
51
+ if (signer && typeof signer === 'object') {
52
+ const signerObj = signer;
53
+ // Check for web3.js Keypair or similar patterns
54
+ if ('publicKey' in signerObj) {
55
+ throw new InvalidSignerError('web3.js signers (Keypair, etc.) are not supported. ' +
56
+ 'Use a base58 address string or TransactionSigner from @solana/kit instead.\n\n' +
57
+ 'Examples:\n' +
58
+ ' - Browser: "base58AddressString"\n' +
59
+ ' - Node.js: createNoopSigner(address("base58AddressString"))');
60
+ }
61
+ // Check for valid @solana/kit signer patterns
62
+ if ('address' in signerObj || typeof signerObj.signTransactions === 'function') {
63
+ // If it has an address property, validate that the address is valid
64
+ if ('address' in signerObj) {
65
+ try {
66
+ // Ensure the address property is a valid Address type
67
+ if (!(0, kit_1.isAddress)(signerObj.address)) {
68
+ throw new InvalidSignerError(`Signer object has invalid address property. Expected Address type from @solana/kit.`);
69
+ }
70
+ }
71
+ catch (error) {
72
+ throw new InvalidSignerError(`Signer object has invalid address property: ${error instanceof Error ? error.message : 'Unknown validation error'}`);
73
+ }
74
+ }
75
+ return;
76
+ }
77
+ // Unknown signer object format
78
+ throw new InvalidSignerError('Invalid signer format. Expected:\n' +
79
+ ' - base58 address string (browser usage)\n' +
80
+ ' - TransactionSigner from @solana/kit (Node.js usage)\n' +
81
+ ' - Object with address property');
82
+ }
83
+ throw new InvalidSignerError('Signer must be a string address or compatible signer object');
84
+ }
85
+ /**
86
+ * Creates TransactionSigner from UniversalSigner input with validation
15
87
  *
16
88
  * This function provides universal compatibility by:
89
+ * - Validating the signer is compatible with @solana/kit
17
90
  * - Converting string addresses to TransactionSigner using createNoopSigner
18
91
  * - Passing through existing TransactionSigner objects unchanged
19
- * - Safely handling different signer interfaces (kit, web3.js, etc.)
20
92
  *
21
93
  * The returned TransactionSigner has both .address property and signing capability,
22
94
  * making it suitable for both PDA derivation and codama instruction building.
23
95
  *
24
- * @param signer - The signer input (string address or signer object)
96
+ * @param signer - The signer input (string address or @solana/kit compatible signer)
25
97
  * @returns TransactionSigner that can be used directly for codama and has .address property
98
+ * @throws {InvalidSignerError} If the signer is not compatible (e.g., web3.js Keypair)
26
99
  *
27
100
  * @example
28
101
  * ```typescript
@@ -31,19 +104,23 @@ const kit_1 = require("@solana/kit");
31
104
  * // borrower.address → Address object for PDA derivation
32
105
  * // borrower → TransactionSigner for codama
33
106
  *
34
- * // CLI usage with wallet object
107
+ * // Node.js usage with TransactionSigner
35
108
  * const borrower = createTransactionSigner(wallet);
36
109
  * // borrower.address → wallet.address for PDA derivation
37
110
  * // borrower → wallet signer for codama
111
+ *
112
+ * // This will throw an error:
113
+ * // createTransactionSigner(keypair); // InvalidSignerError: web3.js signers not supported
38
114
  * ```
39
115
  */
40
116
  function createTransactionSigner(signer) {
117
+ // Validate the signer first
118
+ validateSigner(signer);
41
119
  // Handle string address case (browser usage)
42
120
  if (typeof signer === 'string') {
43
121
  return (0, kit_1.createNoopSigner)((0, kit_1.address)(signer)); // Returns TransactionSigner with .address property
44
122
  }
45
- // Handle signer object cases (CLI and other wallet interfaces)
46
- // These should already be TransactionSigner objects with .address property
123
+ // Handle signer object cases (already validated TransactionSigner objects)
47
124
  return signer;
48
125
  }
49
126
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"signer.js","sourceRoot":"","sources":["../../../src/utils/signer.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AA2CH,0DASC;AAKD,wCAEC;AAKD,0CAEC;AAhED,qCAAgF;AAchF;;;;;;;;;;;;;;;;;;;;;;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AC;IAEvB,6CAA6C;IAC7C,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,IAAA,sBAAgB,EAAC,IAAA,aAAO,EAAC,MAAM,CAAC,CAAC,CAAC,CAAE,mDAAmD;IAChG,CAAC;IAED,2EAA2E;IAC3E,OAAO,MAA2B,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,MAAuB;IACpD,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,MAAuB;IACrD,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC;AACpC,CAAC"}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wuwei-labs/srsly",
3
- "version": "2.0.0-beta.45",
3
+ "version": "2.0.0-beta.46",
4
4
  "description": "",
5
5
  "source": "./src/index.ts",
6
6
  "sideEffects": false,
@@ -1,23 +1,93 @@
1
1
  /**
2
- * Universal signer handling utilities for cross-library compatibility
2
+ * Universal signer handling utilities for @solana/kit compatibility
3
3
  *
4
- * This module provides utilities to handle different signer types across
5
- * @solana/kit, @solana/web3.js, and plain address strings in a unified way.
4
+ * This module provides utilities to handle different signer types in a unified way
5
+ * while ensuring compatibility with @solana/kit. Supports string addresses for
6
+ * browser usage and TransactionSigner objects for Node.js usage.
7
+ *
8
+ * Note: web3.js signers (Keypair, etc.) are explicitly not supported.
9
+ * Use address strings or @solana/kit TransactionSigner objects instead.
6
10
  */
7
- import { createNoopSigner, address } from '@solana/kit';
11
+ import { createNoopSigner, address, isAddress } from '@solana/kit';
8
12
  /**
9
- * Creates TransactionSigner from UniversalSigner input for universal compatibility
13
+ * Error thrown when an invalid signer type is provided
14
+ */
15
+ export class InvalidSignerError extends Error {
16
+ constructor(message) {
17
+ super(message);
18
+ this.name = 'InvalidSignerError';
19
+ }
20
+ }
21
+ /**
22
+ * Validates that a signer is compatible with @solana/kit
23
+ *
24
+ * @param signer - The signer to validate
25
+ * @throws {InvalidSignerError} If the signer is not compatible
26
+ */
27
+ export function validateSigner(signer) {
28
+ if (typeof signer === 'string') {
29
+ // Validate that the string is a valid Solana address
30
+ try {
31
+ // Use @solana/kit's address() function to validate - it will throw if invalid
32
+ address(signer);
33
+ return;
34
+ }
35
+ catch (error) {
36
+ throw new InvalidSignerError(`Invalid address string: "${signer}". ${error instanceof Error ? error.message : 'Unknown validation error'}\n\n` +
37
+ 'Expected a valid base58-encoded Solana address (32-44 characters).\n' +
38
+ 'Examples:\n' +
39
+ ' - "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"\n' +
40
+ ' - "So11111111111111111111111111111111111111112"');
41
+ }
42
+ }
43
+ if (signer && typeof signer === 'object') {
44
+ const signerObj = signer;
45
+ // Check for web3.js Keypair or similar patterns
46
+ if ('publicKey' in signerObj) {
47
+ throw new InvalidSignerError('web3.js signers (Keypair, etc.) are not supported. ' +
48
+ 'Use a base58 address string or TransactionSigner from @solana/kit instead.\n\n' +
49
+ 'Examples:\n' +
50
+ ' - Browser: "base58AddressString"\n' +
51
+ ' - Node.js: createNoopSigner(address("base58AddressString"))');
52
+ }
53
+ // Check for valid @solana/kit signer patterns
54
+ if ('address' in signerObj || typeof signerObj.signTransactions === 'function') {
55
+ // If it has an address property, validate that the address is valid
56
+ if ('address' in signerObj) {
57
+ try {
58
+ // Ensure the address property is a valid Address type
59
+ if (!isAddress(signerObj.address)) {
60
+ throw new InvalidSignerError(`Signer object has invalid address property. Expected Address type from @solana/kit.`);
61
+ }
62
+ }
63
+ catch (error) {
64
+ throw new InvalidSignerError(`Signer object has invalid address property: ${error instanceof Error ? error.message : 'Unknown validation error'}`);
65
+ }
66
+ }
67
+ return;
68
+ }
69
+ // Unknown signer object format
70
+ throw new InvalidSignerError('Invalid signer format. Expected:\n' +
71
+ ' - base58 address string (browser usage)\n' +
72
+ ' - TransactionSigner from @solana/kit (Node.js usage)\n' +
73
+ ' - Object with address property');
74
+ }
75
+ throw new InvalidSignerError('Signer must be a string address or compatible signer object');
76
+ }
77
+ /**
78
+ * Creates TransactionSigner from UniversalSigner input with validation
10
79
  *
11
80
  * This function provides universal compatibility by:
81
+ * - Validating the signer is compatible with @solana/kit
12
82
  * - Converting string addresses to TransactionSigner using createNoopSigner
13
83
  * - Passing through existing TransactionSigner objects unchanged
14
- * - Safely handling different signer interfaces (kit, web3.js, etc.)
15
84
  *
16
85
  * The returned TransactionSigner has both .address property and signing capability,
17
86
  * making it suitable for both PDA derivation and codama instruction building.
18
87
  *
19
- * @param signer - The signer input (string address or signer object)
88
+ * @param signer - The signer input (string address or @solana/kit compatible signer)
20
89
  * @returns TransactionSigner that can be used directly for codama and has .address property
90
+ * @throws {InvalidSignerError} If the signer is not compatible (e.g., web3.js Keypair)
21
91
  *
22
92
  * @example
23
93
  * ```typescript
@@ -26,19 +96,23 @@ import { createNoopSigner, address } from '@solana/kit';
26
96
  * // borrower.address → Address object for PDA derivation
27
97
  * // borrower → TransactionSigner for codama
28
98
  *
29
- * // CLI usage with wallet object
99
+ * // Node.js usage with TransactionSigner
30
100
  * const borrower = createTransactionSigner(wallet);
31
101
  * // borrower.address → wallet.address for PDA derivation
32
102
  * // borrower → wallet signer for codama
103
+ *
104
+ * // This will throw an error:
105
+ * // createTransactionSigner(keypair); // InvalidSignerError: web3.js signers not supported
33
106
  * ```
34
107
  */
35
108
  export function createTransactionSigner(signer) {
109
+ // Validate the signer first
110
+ validateSigner(signer);
36
111
  // Handle string address case (browser usage)
37
112
  if (typeof signer === 'string') {
38
113
  return createNoopSigner(address(signer)); // Returns TransactionSigner with .address property
39
114
  }
40
- // Handle signer object cases (CLI and other wallet interfaces)
41
- // These should already be TransactionSigner objects with .address property
115
+ // Handle signer object cases (already validated TransactionSigner objects)
42
116
  return signer;
43
117
  }
44
118
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"signer.js","sourceRoot":"","sources":["../../../src/utils/signer.ts"],"names":[],"mappings":"AAAA;;;;;GA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A8BG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAAuB;IAC7D,4BAA4B;IAC5B,cAAc,CAAC,MAAM,CAAC,CAAC;IAEvB,6CAA6C;IAC7C,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAE,mDAAmD;IAChG,CAAC;IAED,2EAA2E;IAC3E,OAAO,MAA2B,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,MAAuB;IACpD,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,MAAuB;IACrD,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC;AACpC,CAAC"}
@@ -1,35 +1,55 @@
1
1
  /**
2
- * Universal signer handling utilities for cross-library compatibility
2
+ * Universal signer handling utilities for @solana/kit compatibility
3
3
  *
4
- * This module provides utilities to handle different signer types across
5
- * @solana/kit, @solana/web3.js, and plain address strings in a unified way.
4
+ * This module provides utilities to handle different signer types in a unified way
5
+ * while ensuring compatibility with @solana/kit. Supports string addresses for
6
+ * browser usage and TransactionSigner objects for Node.js usage.
7
+ *
8
+ * Note: web3.js signers (Keypair, etc.) are explicitly not supported.
9
+ * Use address strings or @solana/kit TransactionSigner objects instead.
6
10
  */
7
11
  import { type TransactionSigner } from '@solana/kit';
8
12
  /**
9
- * Enhanced UniversalSigner type that accepts both signer objects and address strings
13
+ * Error thrown when an invalid signer type is provided
14
+ */
15
+ export declare class InvalidSignerError extends Error {
16
+ constructor(message: string);
17
+ }
18
+ /**
19
+ * Universal signer type that supports @solana/kit compatible signers and address strings
20
+ *
21
+ * Supported types:
22
+ * - string: Base58 Solana address (for browser usage)
23
+ * - TransactionSigner: @solana/kit signer object (for Node.js usage)
24
+ * - { address: string }: Kit-compatible signer with address property
25
+ *
26
+ * Note: web3.js signers (Keypair, etc.) are not supported. Use address strings
27
+ * or TransactionSigner objects from @solana/kit instead.
10
28
  */
11
- export type UniversalSigner = string | {
29
+ export type UniversalSigner = string | TransactionSigner | {
12
30
  address: string;
13
- } | {
14
- publicKey: {
15
- toString(): string;
16
- };
17
- } | {
18
- publicKey: string;
19
- } | any;
31
+ };
20
32
  /**
21
- * Creates TransactionSigner from UniversalSigner input for universal compatibility
33
+ * Validates that a signer is compatible with @solana/kit
34
+ *
35
+ * @param signer - The signer to validate
36
+ * @throws {InvalidSignerError} If the signer is not compatible
37
+ */
38
+ export declare function validateSigner(signer: unknown): asserts signer is UniversalSigner;
39
+ /**
40
+ * Creates TransactionSigner from UniversalSigner input with validation
22
41
  *
23
42
  * This function provides universal compatibility by:
43
+ * - Validating the signer is compatible with @solana/kit
24
44
  * - Converting string addresses to TransactionSigner using createNoopSigner
25
45
  * - Passing through existing TransactionSigner objects unchanged
26
- * - Safely handling different signer interfaces (kit, web3.js, etc.)
27
46
  *
28
47
  * The returned TransactionSigner has both .address property and signing capability,
29
48
  * making it suitable for both PDA derivation and codama instruction building.
30
49
  *
31
- * @param signer - The signer input (string address or signer object)
50
+ * @param signer - The signer input (string address or @solana/kit compatible signer)
32
51
  * @returns TransactionSigner that can be used directly for codama and has .address property
52
+ * @throws {InvalidSignerError} If the signer is not compatible (e.g., web3.js Keypair)
33
53
  *
34
54
  * @example
35
55
  * ```typescript
@@ -38,10 +58,13 @@ export type UniversalSigner = string | {
38
58
  * // borrower.address → Address object for PDA derivation
39
59
  * // borrower → TransactionSigner for codama
40
60
  *
41
- * // CLI usage with wallet object
61
+ * // Node.js usage with TransactionSigner
42
62
  * const borrower = createTransactionSigner(wallet);
43
63
  * // borrower.address → wallet.address for PDA derivation
44
64
  * // borrower → wallet signer for codama
65
+ *
66
+ * // This will throw an error:
67
+ * // createTransactionSigner(keypair); // InvalidSignerError: web3.js signers not supported
45
68
  * ```
46
69
  */
47
70
  export declare function createTransactionSigner(signer: UniversalSigner): TransactionSigner;
@@ -1 +1 @@
1
- {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../../src/utils/signer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAA6B,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhF;;GAEG;AACH,MAAM,MAAM,eAAe,GACvB,MAAM,GACN;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,GACnB;IAAE,SAAS,EAAE;QAAE,QAAQ,IAAI,MAAM,CAAA;KAAE,CAAA;CAAE,GACrC;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GACrB,GAAG,CAAC;AAGR;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,eAAe,GAAG,iBAAiB,CASlF;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,IAAI,OAAO,CAAC,eAAe,EAAE,MAAM,CAAC,CAElG;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,IAAI,MAAM,CAEzE"}
1
+ {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../../src/utils/signer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAwC,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAG3F;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;gBAC/B,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,eAAe,GACvB,MAAM,GACN,iBAAiB,GACjB;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAExB;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,IAAI,eAAe,CAgEjF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,eAAe,GAAG,iBAAiB,CAWlF;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,IAAI,OAAO,CAAC,eAAe,EAAE,MAAM,CAAC,CAElG;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,IAAI,MAAM,CAEzE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wuwei-labs/srsly",
3
- "version": "2.0.0-beta.45",
3
+ "version": "2.0.0-beta.46",
4
4
  "description": "",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "types": "./dist/types/index.d.ts",