@moon-x/solana-adapter 0.1.0 → 0.2.0
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/README.md +1 -1
- package/dist/index.d.mts +43 -15
- package/dist/index.d.ts +43 -15
- package/dist/index.js +32 -18
- package/dist/index.mjs +30 -17
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ const signer = createSolanaSigner({
|
|
|
33
33
|
walletId, // the Solana wallet the agent was provisioned for
|
|
34
34
|
address, // base58 wallet pubkey (needed to attach the signature)
|
|
35
35
|
baseUrl, // wallets backend URL
|
|
36
|
-
|
|
36
|
+
secretKey, // moon_sk_* (server-only; the sign routes are secret-key-only)
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
// Arbitrary message → 64-byte ed25519 signature
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
2
|
+
import { Ed25519SignFn } from '@moon-x/signing-codec/solana';
|
|
3
|
+
export { Ed25519SignFn } from '@moon-x/signing-codec/solana';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Connection + identity for a Solana ephemeral signer. `apiPrivHex` is
|
|
@@ -22,10 +24,16 @@ interface SolanaSignerConfig {
|
|
|
22
24
|
* by signer pubkey.
|
|
23
25
|
*/
|
|
24
26
|
address: string;
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Wallets backend base URL (no trailing slash). Optional — defaults to
|
|
29
|
+
* the standard MoonX deployment. Override only for local/dev.
|
|
30
|
+
*/
|
|
31
|
+
baseUrl?: string;
|
|
32
|
+
/**
|
|
33
|
+
* MoonX secret key (`moon_sk_*`). The ephemeral-signer routes are
|
|
34
|
+
* secret-key-only; server-only, never expose to the browser.
|
|
35
|
+
*/
|
|
36
|
+
secretKey: string;
|
|
29
37
|
/** Optional fetch override — e.g. for Next.js route handlers or test stubs. */
|
|
30
38
|
fetchImpl?: typeof fetch;
|
|
31
39
|
}
|
|
@@ -33,19 +41,35 @@ declare class SolanaSchemeMismatchError extends Error {
|
|
|
33
41
|
constructor(scheme: string);
|
|
34
42
|
}
|
|
35
43
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
44
|
+
* Build an `Ed25519SignFn` backed by a MoonX ephemeral signer. This is the
|
|
45
|
+
* *transport* half — it owns the `/ephemeral-signers/sign` HTTP call, so it
|
|
46
|
+
* needs the backend `baseUrl` and the app `secretKey` (server-only). Pass
|
|
47
|
+
* the result to `new MoonXSolanaSigner(sign, address)`.
|
|
38
48
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
|
|
49
|
+
* Exposed separately so the chain logic and the transport stay decoupled:
|
|
50
|
+
* any other `Ed25519SignFn` (e.g. the iframe's MPC sign fn, or a test stub)
|
|
51
|
+
* drives the same `MoonXSolanaSigner` without going through here.
|
|
52
|
+
*/
|
|
53
|
+
declare function ephemeralSignerEd25519SignFn(cfg: SolanaSignerConfig): Ed25519SignFn;
|
|
54
|
+
/**
|
|
55
|
+
* Chain-aware Solana signer: produces the bytes to sign and attaches the
|
|
56
|
+
* signature, independent of *how* the bytes get signed. All chain logic
|
|
57
|
+
* lives in @moon-x/signing-codec/solana; this class just binds it to a
|
|
58
|
+
* single `Ed25519SignFn` and exposes intent-level methods.
|
|
59
|
+
*
|
|
60
|
+
* Two ways to construct:
|
|
61
|
+
* - `new MoonXSolanaSigner(sign, address)` with any `Ed25519SignFn` —
|
|
62
|
+
* transport-independent. `address` (base58 pubkey) is needed only for
|
|
63
|
+
* `signTransaction`, since Solana keys signatures by signer pubkey.
|
|
64
|
+
* - `new MoonXSolanaSigner(config)` with the ephemeral-signer connection +
|
|
65
|
+
* secret key — the server-side convenience; equivalent to
|
|
66
|
+
* `new MoonXSolanaSigner(ephemeralSignerEd25519SignFn(config), config.address)`.
|
|
43
67
|
*/
|
|
44
68
|
declare class MoonXSolanaSigner {
|
|
45
|
-
private readonly cfg;
|
|
46
|
-
constructor(cfg: SolanaSignerConfig);
|
|
47
|
-
/** Ephemeral-signer backend: sign raw bytes, return the 64-byte sig. */
|
|
48
69
|
private readonly sign;
|
|
70
|
+
private readonly address?;
|
|
71
|
+
constructor(sign: Ed25519SignFn, address?: string);
|
|
72
|
+
constructor(config: SolanaSignerConfig);
|
|
49
73
|
/**
|
|
50
74
|
* Sign an arbitrary message. Accepts a UTF-8 string or raw bytes and
|
|
51
75
|
* returns the 64-byte ed25519 signature, verifiable against the wallet's
|
|
@@ -59,7 +83,11 @@ declare class MoonXSolanaSigner {
|
|
|
59
83
|
*/
|
|
60
84
|
signTransaction(transaction: Transaction | VersionedTransaction): Promise<Uint8Array>;
|
|
61
85
|
}
|
|
62
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* Convenience factory for the server-side ephemeral-signer path.
|
|
88
|
+
* Equivalent to `new MoonXSolanaSigner(config)`. For a custom transport,
|
|
89
|
+
* construct the class directly with your own `Ed25519SignFn` + address.
|
|
90
|
+
*/
|
|
63
91
|
declare function createSolanaSigner(cfg: SolanaSignerConfig): MoonXSolanaSigner;
|
|
64
92
|
|
|
65
|
-
export { MoonXSolanaSigner, SolanaSchemeMismatchError, type SolanaSignerConfig, createSolanaSigner };
|
|
93
|
+
export { MoonXSolanaSigner, SolanaSchemeMismatchError, type SolanaSignerConfig, createSolanaSigner, ephemeralSignerEd25519SignFn };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
2
|
+
import { Ed25519SignFn } from '@moon-x/signing-codec/solana';
|
|
3
|
+
export { Ed25519SignFn } from '@moon-x/signing-codec/solana';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Connection + identity for a Solana ephemeral signer. `apiPrivHex` is
|
|
@@ -22,10 +24,16 @@ interface SolanaSignerConfig {
|
|
|
22
24
|
* by signer pubkey.
|
|
23
25
|
*/
|
|
24
26
|
address: string;
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Wallets backend base URL (no trailing slash). Optional — defaults to
|
|
29
|
+
* the standard MoonX deployment. Override only for local/dev.
|
|
30
|
+
*/
|
|
31
|
+
baseUrl?: string;
|
|
32
|
+
/**
|
|
33
|
+
* MoonX secret key (`moon_sk_*`). The ephemeral-signer routes are
|
|
34
|
+
* secret-key-only; server-only, never expose to the browser.
|
|
35
|
+
*/
|
|
36
|
+
secretKey: string;
|
|
29
37
|
/** Optional fetch override — e.g. for Next.js route handlers or test stubs. */
|
|
30
38
|
fetchImpl?: typeof fetch;
|
|
31
39
|
}
|
|
@@ -33,19 +41,35 @@ declare class SolanaSchemeMismatchError extends Error {
|
|
|
33
41
|
constructor(scheme: string);
|
|
34
42
|
}
|
|
35
43
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
44
|
+
* Build an `Ed25519SignFn` backed by a MoonX ephemeral signer. This is the
|
|
45
|
+
* *transport* half — it owns the `/ephemeral-signers/sign` HTTP call, so it
|
|
46
|
+
* needs the backend `baseUrl` and the app `secretKey` (server-only). Pass
|
|
47
|
+
* the result to `new MoonXSolanaSigner(sign, address)`.
|
|
38
48
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
|
|
49
|
+
* Exposed separately so the chain logic and the transport stay decoupled:
|
|
50
|
+
* any other `Ed25519SignFn` (e.g. the iframe's MPC sign fn, or a test stub)
|
|
51
|
+
* drives the same `MoonXSolanaSigner` without going through here.
|
|
52
|
+
*/
|
|
53
|
+
declare function ephemeralSignerEd25519SignFn(cfg: SolanaSignerConfig): Ed25519SignFn;
|
|
54
|
+
/**
|
|
55
|
+
* Chain-aware Solana signer: produces the bytes to sign and attaches the
|
|
56
|
+
* signature, independent of *how* the bytes get signed. All chain logic
|
|
57
|
+
* lives in @moon-x/signing-codec/solana; this class just binds it to a
|
|
58
|
+
* single `Ed25519SignFn` and exposes intent-level methods.
|
|
59
|
+
*
|
|
60
|
+
* Two ways to construct:
|
|
61
|
+
* - `new MoonXSolanaSigner(sign, address)` with any `Ed25519SignFn` —
|
|
62
|
+
* transport-independent. `address` (base58 pubkey) is needed only for
|
|
63
|
+
* `signTransaction`, since Solana keys signatures by signer pubkey.
|
|
64
|
+
* - `new MoonXSolanaSigner(config)` with the ephemeral-signer connection +
|
|
65
|
+
* secret key — the server-side convenience; equivalent to
|
|
66
|
+
* `new MoonXSolanaSigner(ephemeralSignerEd25519SignFn(config), config.address)`.
|
|
43
67
|
*/
|
|
44
68
|
declare class MoonXSolanaSigner {
|
|
45
|
-
private readonly cfg;
|
|
46
|
-
constructor(cfg: SolanaSignerConfig);
|
|
47
|
-
/** Ephemeral-signer backend: sign raw bytes, return the 64-byte sig. */
|
|
48
69
|
private readonly sign;
|
|
70
|
+
private readonly address?;
|
|
71
|
+
constructor(sign: Ed25519SignFn, address?: string);
|
|
72
|
+
constructor(config: SolanaSignerConfig);
|
|
49
73
|
/**
|
|
50
74
|
* Sign an arbitrary message. Accepts a UTF-8 string or raw bytes and
|
|
51
75
|
* returns the 64-byte ed25519 signature, verifiable against the wallet's
|
|
@@ -59,7 +83,11 @@ declare class MoonXSolanaSigner {
|
|
|
59
83
|
*/
|
|
60
84
|
signTransaction(transaction: Transaction | VersionedTransaction): Promise<Uint8Array>;
|
|
61
85
|
}
|
|
62
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* Convenience factory for the server-side ephemeral-signer path.
|
|
88
|
+
* Equivalent to `new MoonXSolanaSigner(config)`. For a custom transport,
|
|
89
|
+
* construct the class directly with your own `Ed25519SignFn` + address.
|
|
90
|
+
*/
|
|
63
91
|
declare function createSolanaSigner(cfg: SolanaSignerConfig): MoonXSolanaSigner;
|
|
64
92
|
|
|
65
|
-
export { MoonXSolanaSigner, SolanaSchemeMismatchError, type SolanaSignerConfig, createSolanaSigner };
|
|
93
|
+
export { MoonXSolanaSigner, SolanaSchemeMismatchError, type SolanaSignerConfig, createSolanaSigner, ephemeralSignerEd25519SignFn };
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,8 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
MoonXSolanaSigner: () => MoonXSolanaSigner,
|
|
24
24
|
SolanaSchemeMismatchError: () => SolanaSchemeMismatchError,
|
|
25
|
-
createSolanaSigner: () => createSolanaSigner
|
|
25
|
+
createSolanaSigner: () => createSolanaSigner,
|
|
26
|
+
ephemeralSignerEd25519SignFn: () => ephemeralSignerEd25519SignFn
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(src_exports);
|
|
28
29
|
|
|
@@ -96,22 +97,29 @@ function requireEd25519(result) {
|
|
|
96
97
|
}
|
|
97
98
|
return hexToBytes(sigHex);
|
|
98
99
|
}
|
|
100
|
+
function ephemeralSignerEd25519SignFn(cfg) {
|
|
101
|
+
return async (message) => {
|
|
102
|
+
const result = await (0, import_sdk.signWithEphemeralSigner)({
|
|
103
|
+
apiPubHex: cfg.apiPubHex,
|
|
104
|
+
apiPrivHex: cfg.apiPrivHex,
|
|
105
|
+
walletId: cfg.walletId,
|
|
106
|
+
rawSigningPayloadHex: bytesToHex(message),
|
|
107
|
+
baseUrl: cfg.baseUrl,
|
|
108
|
+
secretKey: cfg.secretKey,
|
|
109
|
+
fetchImpl: cfg.fetchImpl
|
|
110
|
+
});
|
|
111
|
+
return requireEd25519(result);
|
|
112
|
+
};
|
|
113
|
+
}
|
|
99
114
|
var MoonXSolanaSigner = class {
|
|
100
|
-
constructor(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
rawSigningPayloadHex: bytesToHex(message),
|
|
109
|
-
baseUrl: this.cfg.baseUrl,
|
|
110
|
-
publishableKey: this.cfg.publishableKey,
|
|
111
|
-
fetchImpl: this.cfg.fetchImpl
|
|
112
|
-
});
|
|
113
|
-
return requireEd25519(result);
|
|
114
|
-
};
|
|
115
|
+
constructor(signOrConfig, address) {
|
|
116
|
+
if (typeof signOrConfig === "function") {
|
|
117
|
+
this.sign = signOrConfig;
|
|
118
|
+
this.address = address;
|
|
119
|
+
} else {
|
|
120
|
+
this.sign = ephemeralSignerEd25519SignFn(signOrConfig);
|
|
121
|
+
this.address = signOrConfig.address;
|
|
122
|
+
}
|
|
115
123
|
}
|
|
116
124
|
/**
|
|
117
125
|
* Sign an arbitrary message. Accepts a UTF-8 string or raw bytes and
|
|
@@ -127,7 +135,12 @@ var MoonXSolanaSigner = class {
|
|
|
127
135
|
* `connection.sendRawTransaction`.
|
|
128
136
|
*/
|
|
129
137
|
signTransaction(transaction) {
|
|
130
|
-
|
|
138
|
+
if (!this.address) {
|
|
139
|
+
throw new Error(
|
|
140
|
+
"MoonXSolanaSigner: address is required to sign a transaction (Solana keys signatures by signer pubkey). Pass it as the second constructor arg, or use SolanaSignerConfig.address."
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
return signSolanaTransaction(this.sign, transaction, this.address);
|
|
131
144
|
}
|
|
132
145
|
};
|
|
133
146
|
function createSolanaSigner(cfg) {
|
|
@@ -137,5 +150,6 @@ function createSolanaSigner(cfg) {
|
|
|
137
150
|
0 && (module.exports = {
|
|
138
151
|
MoonXSolanaSigner,
|
|
139
152
|
SolanaSchemeMismatchError,
|
|
140
|
-
createSolanaSigner
|
|
153
|
+
createSolanaSigner,
|
|
154
|
+
ephemeralSignerEd25519SignFn
|
|
141
155
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -74,22 +74,29 @@ function requireEd25519(result) {
|
|
|
74
74
|
}
|
|
75
75
|
return hexToBytes(sigHex);
|
|
76
76
|
}
|
|
77
|
+
function ephemeralSignerEd25519SignFn(cfg) {
|
|
78
|
+
return async (message) => {
|
|
79
|
+
const result = await signWithEphemeralSigner({
|
|
80
|
+
apiPubHex: cfg.apiPubHex,
|
|
81
|
+
apiPrivHex: cfg.apiPrivHex,
|
|
82
|
+
walletId: cfg.walletId,
|
|
83
|
+
rawSigningPayloadHex: bytesToHex(message),
|
|
84
|
+
baseUrl: cfg.baseUrl,
|
|
85
|
+
secretKey: cfg.secretKey,
|
|
86
|
+
fetchImpl: cfg.fetchImpl
|
|
87
|
+
});
|
|
88
|
+
return requireEd25519(result);
|
|
89
|
+
};
|
|
90
|
+
}
|
|
77
91
|
var MoonXSolanaSigner = class {
|
|
78
|
-
constructor(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
rawSigningPayloadHex: bytesToHex(message),
|
|
87
|
-
baseUrl: this.cfg.baseUrl,
|
|
88
|
-
publishableKey: this.cfg.publishableKey,
|
|
89
|
-
fetchImpl: this.cfg.fetchImpl
|
|
90
|
-
});
|
|
91
|
-
return requireEd25519(result);
|
|
92
|
-
};
|
|
92
|
+
constructor(signOrConfig, address) {
|
|
93
|
+
if (typeof signOrConfig === "function") {
|
|
94
|
+
this.sign = signOrConfig;
|
|
95
|
+
this.address = address;
|
|
96
|
+
} else {
|
|
97
|
+
this.sign = ephemeralSignerEd25519SignFn(signOrConfig);
|
|
98
|
+
this.address = signOrConfig.address;
|
|
99
|
+
}
|
|
93
100
|
}
|
|
94
101
|
/**
|
|
95
102
|
* Sign an arbitrary message. Accepts a UTF-8 string or raw bytes and
|
|
@@ -105,7 +112,12 @@ var MoonXSolanaSigner = class {
|
|
|
105
112
|
* `connection.sendRawTransaction`.
|
|
106
113
|
*/
|
|
107
114
|
signTransaction(transaction) {
|
|
108
|
-
|
|
115
|
+
if (!this.address) {
|
|
116
|
+
throw new Error(
|
|
117
|
+
"MoonXSolanaSigner: address is required to sign a transaction (Solana keys signatures by signer pubkey). Pass it as the second constructor arg, or use SolanaSignerConfig.address."
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
return signSolanaTransaction(this.sign, transaction, this.address);
|
|
109
121
|
}
|
|
110
122
|
};
|
|
111
123
|
function createSolanaSigner(cfg) {
|
|
@@ -114,5 +126,6 @@ function createSolanaSigner(cfg) {
|
|
|
114
126
|
export {
|
|
115
127
|
MoonXSolanaSigner,
|
|
116
128
|
SolanaSchemeMismatchError,
|
|
117
|
-
createSolanaSigner
|
|
129
|
+
createSolanaSigner,
|
|
130
|
+
ephemeralSignerEd25519SignFn
|
|
118
131
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moon-x/solana-adapter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Chain-aware Solana signing helpers for MoonX ephemeral signers. Serializes the message bytes and assembles ready-to-broadcast transactions/signatures so integrators never hand-roll payload construction.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@moon-x/core": "0.
|
|
34
|
+
"@moon-x/core": "0.9.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@solana/web3.js": "^1.98.0"
|