@talismn/solana 0.0.10 → 1.0.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/LICENSE +253 -674
- package/dist/index.d.mts +195 -63
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +195 -63
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +198 -186
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +181 -154
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,68 +1,200 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Instruction, Transaction, TransactionMessageBytesBase64 } from "@solana/kit";
|
|
2
|
+
//#region src/utils/chains.d.ts
|
|
3
3
|
declare const SOLANA_CHAINS: readonly ["solana:mainnet", "solana:devnet", "solana:testnet", "solana:localnet"];
|
|
4
4
|
type SolanaChainId = (typeof SOLANA_CHAINS)[number];
|
|
5
|
-
declare const getSolNetworkId: (chain: SolanaChainId) => "solana-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
declare const getSolNetworkId: (chain: SolanaChainId) => "solana-devnet" | "solana-localnet" | "solana-mainnet" | "solana-testnet";
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/utils/offchainMessage.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Wraps a raw message in the off-chain message envelope that hardware wallets sign.
|
|
10
|
+
* Returns `null` if the message cannot be wrapped (binary content, empty, or too long).
|
|
11
|
+
*/
|
|
12
|
+
declare const serializeOffchainMessage: (message: Uint8Array, signerPublicKey: Uint8Array) => Uint8Array | null;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region ../../node_modules/.pnpm/@solana+nominal-types@6.10.0_typescript@7.0.2/node_modules/@solana/nominal-types/dist/types/index.d.ts
|
|
15
|
+
type StringEncoding = 'base58' | 'base64';
|
|
16
|
+
/**
|
|
17
|
+
* Use this to produce a new type that satisfies the original type, but not the other way around.
|
|
18
|
+
* That is to say, the branded type is acceptable wherever the original type is specified, but
|
|
19
|
+
* wherever the branded type is specified, the original type will be insufficient.
|
|
20
|
+
*
|
|
21
|
+
* You can use this to create specialized instances of strings, numbers, objects, and more which
|
|
22
|
+
* you would like to assert are special in some way (eg. numbers that are non-negative, strings
|
|
23
|
+
* which represent the names of foods, objects that have passed validation).
|
|
24
|
+
*
|
|
25
|
+
* @typeParam T - The base type to brand
|
|
26
|
+
* @typeParam TBrandName - A string that identifies a particular brand. Branded types with identical
|
|
27
|
+
* names will satisfy each other so long as their base types satisfy each other. Branded types with
|
|
28
|
+
* different names will never satisfy each other.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const unverifiedName = 'Alice';
|
|
33
|
+
* const verifiedName = unverifiedName as Brand<'Alice', 'VerifiedName'>;
|
|
34
|
+
*
|
|
35
|
+
* 'Alice' satisfies Brand<string, 'VerifiedName'>; // ERROR
|
|
36
|
+
* 'Alice' satisfies Brand<'Alice', 'VerifiedName'>; // ERROR
|
|
37
|
+
* unverifiedName satisfies Brand<string, 'VerifiedName'>; // ERROR
|
|
38
|
+
* verifiedName satisfies Brand<'Bob', 'VerifiedName'>; // ERROR
|
|
39
|
+
* verifiedName satisfies Brand<'Alice', 'VerifiedName'>; // OK
|
|
40
|
+
* verifiedName satisfies Brand<string, 'VerifiedName'>; // OK
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
type Brand<T, TBrandName extends string> = NominalType<'brand', TBrandName> & T;
|
|
44
|
+
/**
|
|
45
|
+
* Use this to produce a new type that satisfies the original string type, but adds extra type
|
|
46
|
+
* information that marks the string as being encoded in a particular format.
|
|
47
|
+
*
|
|
48
|
+
* @typeParam T - The underlying string type
|
|
49
|
+
* @typeParam TEncoding - The encoding format of the string
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* const untaggedString = 'dv1ZAGvdsz5hHLwWXsVnM94hWf1pjbKVau1QVkaMJ92';
|
|
54
|
+
* const encodedString = untaggedString as EncodedString<typeof untaggedString, 'base58'>;
|
|
55
|
+
*
|
|
56
|
+
* encodedString satisfies EncodedString<'dv1ZAGvdsz5hHLwWXsVnM94hWf1pjbKVau1QVkaMJ92', 'base58'>; // OK
|
|
57
|
+
* encodedString satisfies EncodedString<string, 'base58'>; // OK
|
|
58
|
+
* encodedString satisfies EncodedString<string, 'base64'>; // ERROR
|
|
59
|
+
* untaggedString satisfies EncodedString<string, 'base58'>; // ERROR
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
type EncodedString<T extends string, TEncoding extends StringEncoding> = NominalType<'stringEncoding', TEncoding> & T;
|
|
63
|
+
/**
|
|
64
|
+
* Use this to produce a nominal type.
|
|
65
|
+
*
|
|
66
|
+
* This can be intersected with other base types to produce custom branded types.
|
|
67
|
+
*
|
|
68
|
+
* @typeParam TKey - The name of the nominal type. This distinguishes one nominal type from another.
|
|
69
|
+
* @typeParam TMarker - The type of the value the nominal type can take.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* type SweeteningSubstance = 'aspartame' | 'cane-sugar' | 'stevia';
|
|
74
|
+
* type Sweetener<T extends SweeteningSubstance> = NominalType<'sweetener', T>;
|
|
75
|
+
*
|
|
76
|
+
* // This function accepts sweetened foods, except those with aspartame.
|
|
77
|
+
* declare function eat(food: string & Sweetener<Exclude<SweeteningSubstance, 'aspartame'>>): void;
|
|
78
|
+
*
|
|
79
|
+
* const artificiallySweetenedDessert = 'ice-cream' as string & Sweetener<'aspartame'>;
|
|
80
|
+
* eat(artificiallySweetenedDessert); // ERROR
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
type NominalType<TKey extends string, TMarker extends string> = { readonly [K in `__${TKey}:@solana/kit`]: TMarker; };
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region ../../node_modules/.pnpm/@solana+addresses@6.10.0_fastestsmallesttextencoderdecoder@1.0.22_typescript@7.0.2/node_modules/@solana/addresses/dist/types/address.d.ts
|
|
86
|
+
/**
|
|
87
|
+
* Represents a string that validates as a Solana address. Functions that require well-formed
|
|
88
|
+
* addresses should specify their inputs in terms of this type.
|
|
89
|
+
*
|
|
90
|
+
* Whenever you need to validate an arbitrary string as a base58-encoded address, use the
|
|
91
|
+
* {@link address}, {@link assertIsAddress}, or {@link isAddress} functions in this package.
|
|
92
|
+
*/
|
|
93
|
+
type Address<TAddress extends string = string> = Brand<EncodedString<TAddress, 'base58'>, 'Address'>;
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/utils/transaction.d.ts
|
|
96
|
+
/**
|
|
97
|
+
* A Solana transaction: raw wire message bytes plus a signer-address → signature map.
|
|
98
|
+
* Kit's decoder/encoder handles both legacy and v0 wire formats transparently.
|
|
99
|
+
*/
|
|
100
|
+
type SolTransaction = Transaction;
|
|
101
|
+
type SolTransactionInfo = {
|
|
102
|
+
version: "legacy" | 0 | 1;
|
|
103
|
+
/** compiled lifetime token — the recent blockhash (or nonce for durable-nonce transactions) */
|
|
104
|
+
recentBlockhash: string;
|
|
105
|
+
/** first static account, the account that pays the transaction fee */
|
|
106
|
+
feePayer: string;
|
|
107
|
+
/** all required signer addresses, in wire order */
|
|
108
|
+
signerAddresses: string[];
|
|
109
|
+
/**
|
|
110
|
+
* The account expected to sign in wallet flows.
|
|
111
|
+
* `undefined` when the transaction has several signers (e.g. sponsored/partially-signed
|
|
112
|
+
* dapp transactions) — callers use this to fall back to the dapp-provided address.
|
|
113
|
+
*/
|
|
114
|
+
address: string | undefined;
|
|
115
|
+
/**
|
|
116
|
+
* canonical (fee payer) base58 transaction signature, verified against the message bytes;
|
|
117
|
+
* null when the fee payer hasn't signed
|
|
118
|
+
*/
|
|
119
|
+
signature: string | null;
|
|
18
120
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
declare const
|
|
23
|
-
declare const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
121
|
+
declare const parseTransactionInfo: (tx: SolTransaction) => SolTransactionInfo;
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/utils/serialization.d.ts
|
|
124
|
+
declare const transactionFromBytes: (bytes: Uint8Array) => SolTransaction;
|
|
125
|
+
declare const transactionToBytes: (tx: SolTransaction) => Uint8Array;
|
|
126
|
+
/** base58 of the wire-format transaction — both legacy and v0, wire-compatible with web3.js */
|
|
127
|
+
declare const serializeTransaction: (tx: SolTransaction) => string;
|
|
128
|
+
declare const deserializeTransaction: (transaction: string) => SolTransaction;
|
|
129
|
+
/** decoded compiled message — legacy and v0 wire formats are handled transparently */
|
|
130
|
+
declare const getCompiledMessage: (tx: SolTransaction) => import("@solana/kit").CompiledTransactionMessage & Readonly<{
|
|
131
|
+
lifetimeToken: string;
|
|
132
|
+
}>;
|
|
133
|
+
/**
|
|
134
|
+
* Whether the bytes parse as a complete compiled transaction message (legacy or v0).
|
|
135
|
+
* Wallets must refuse to sign such a payload as a "message": Solana software accounts sign raw
|
|
136
|
+
* message bytes with no domain separator, so the resulting ed25519 signature would double as a
|
|
137
|
+
* valid transaction signature.
|
|
138
|
+
*/
|
|
139
|
+
declare const isCompiledTransactionMessage: (bytes: Uint8Array) => boolean;
|
|
140
|
+
/** base64 of the compiled message bytes, the format `getFeeForMessage` expects */
|
|
141
|
+
declare const getMessageBase64: (tx: SolTransaction) => TransactionMessageBytesBase64;
|
|
142
|
+
declare const buildUnsignedTransaction: ({ feePayer, blockhash, lastValidBlockHeight, instructions, version }: {
|
|
143
|
+
feePayer: string;
|
|
144
|
+
blockhash: string;
|
|
145
|
+
lastValidBlockHeight: bigint;
|
|
146
|
+
instructions: Instruction[];
|
|
147
|
+
version?: "legacy" | 0;
|
|
148
|
+
}) => SolTransaction;
|
|
149
|
+
/**
|
|
150
|
+
* Returns a copy of the transaction with its lifetime token (recent blockhash) replaced,
|
|
151
|
+
* re-encoding the compiled message. Existing signatures are reset to null — changing the
|
|
152
|
+
* blockhash invalidates them.
|
|
153
|
+
*/
|
|
154
|
+
declare const setTransactionBlockhash: (tx: SolTransaction, blockhash: string) => SolTransaction;
|
|
155
|
+
declare const txToHumanJSON: (tx: string | SolTransaction) => {
|
|
156
|
+
version: "legacy" | 0 | 1;
|
|
157
|
+
signatures: (string | null)[];
|
|
158
|
+
feePayer: Address;
|
|
159
|
+
recentBlockhash: string | null;
|
|
160
|
+
staticAccountKeys: readonly string[];
|
|
161
|
+
addressTableLookups: {
|
|
162
|
+
accountKey: string;
|
|
163
|
+
writableIndexes: number[];
|
|
164
|
+
readonlyIndexes: number[];
|
|
165
|
+
}[];
|
|
166
|
+
instructions: {
|
|
167
|
+
programIdIndex: number;
|
|
168
|
+
programId: Address;
|
|
169
|
+
accounts: {
|
|
170
|
+
index: number;
|
|
171
|
+
pubkey: Address;
|
|
172
|
+
isSigner: boolean;
|
|
173
|
+
isWritable: boolean;
|
|
33
174
|
}[];
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
programId: string;
|
|
37
|
-
accounts: {
|
|
38
|
-
index: number;
|
|
39
|
-
pubkey: string;
|
|
40
|
-
}[];
|
|
41
|
-
data: string;
|
|
42
|
-
}[];
|
|
43
|
-
} | {
|
|
44
|
-
type: string;
|
|
45
|
-
signatures: (string | null)[];
|
|
46
|
-
feePayer: string | null;
|
|
47
|
-
recentBlockhash: string | null;
|
|
48
|
-
instructions: {
|
|
49
|
-
programId: string;
|
|
50
|
-
accounts: {
|
|
51
|
-
pubkey: string;
|
|
52
|
-
isSigner: boolean;
|
|
53
|
-
isWritable: boolean;
|
|
54
|
-
}[];
|
|
55
|
-
data: string;
|
|
56
|
-
}[];
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
declare const getKeypair: (secretKey: Uint8Array) => Keypair;
|
|
60
|
-
|
|
61
|
-
declare const isVersionedTransaction: (transaction: Transaction | VersionedTransaction) => transaction is VersionedTransaction;
|
|
62
|
-
declare const parseTransactionInfo: (tx: Transaction | VersionedTransaction) => {
|
|
63
|
-
recentBlockhash: string | undefined;
|
|
64
|
-
address: string | undefined;
|
|
65
|
-
signature: string | null;
|
|
175
|
+
data: string;
|
|
176
|
+
}[];
|
|
66
177
|
};
|
|
67
|
-
|
|
68
|
-
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region src/utils/signing.d.ts
|
|
180
|
+
/**
|
|
181
|
+
* Returns a copy of the transaction with `signature` attached for `address`.
|
|
182
|
+
* Throws if `address` is not a required signer of the transaction (the signatures
|
|
183
|
+
* map is keyed in wire order at decode time — adding a key would corrupt re-encoding).
|
|
184
|
+
*/
|
|
185
|
+
declare const attachTransactionSignature: (tx: SolTransaction, address: string, signature: Uint8Array) => SolTransaction;
|
|
186
|
+
/**
|
|
187
|
+
* Returns the signature attached for `address`, verified against the transaction's message
|
|
188
|
+
* bytes; null when missing, all-zeros, or invalid. Unlike `parseTransactionInfo`, this checks
|
|
189
|
+
* a specific signer's slot, so it works on transactions with co-signers.
|
|
190
|
+
*/
|
|
191
|
+
declare const getVerifiedTransactionSignature: (tx: SolTransaction, address: string) => Uint8Array | null;
|
|
192
|
+
/**
|
|
193
|
+
* Signs the transaction's message bytes with the given ed25519 secret key and
|
|
194
|
+
* attaches the signature. Signing happens with @noble/curves (via @talismn/crypto),
|
|
195
|
+
* not WebCrypto — Ed25519 subtle crypto is too recent for the extension's support matrix.
|
|
196
|
+
*/
|
|
197
|
+
declare const signTransactionWithSecretKey: (tx: SolTransaction, secretKey: Uint8Array, expectedAddress?: string) => SolTransaction;
|
|
198
|
+
//#endregion
|
|
199
|
+
export { SOLANA_CHAINS, SolTransaction, SolTransactionInfo, SolanaChainId, attachTransactionSignature, buildUnsignedTransaction, deserializeTransaction, getCompiledMessage, getMessageBase64, getSolNetworkId, getVerifiedTransactionSignature, isCompiledTransactionMessage, parseTransactionInfo, serializeOffchainMessage, serializeTransaction, setTransactionBlockhash, signTransactionWithSecretKey, transactionFromBytes, transactionToBytes, txToHumanJSON };
|
|
200
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/utils/chains.ts","../src/utils/offchainMessage.ts","../../../node_modules/.pnpm/@solana+nominal-types@6.10.0_typescript@7.0.2/node_modules/@solana/nominal-types/dist/types/index.d.ts","../../../node_modules/.pnpm/@solana+addresses@6.10.0_fastestsmallesttextencoderdecoder@1.0.22_typescript@7.0.2/node_modules/@solana/addresses/dist/types/address.d.ts","../src/utils/transaction.ts","../src/utils/serialization.ts","../src/utils/signing.ts"],"x_google_ignoreList":[2,3],"mappings":";;cAAa;KAOD,wBAAwB;cAEvB,kBAAe,OAAW;;;;;;;cCoC1B,2BAAwB,SAC1B,YAAU,iBACF,eAChB;;;KCzBE;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAiDO,MAAM,GAAG,6BAA6B,qBAAqB,cAAc;;;;;;;;;;;;;;;;;;;KAoCzE,cAAc,kBAAkB,kBAAkB,kBAAkB,8BAA8B,aAAa;;;;;;;;;;;;;;;;;;;;;KAqB/G,YAAY,qBAAqB,sCAC/B,UAAU,qBAAqB;;;;;;;;;;KCzHjC,QAAQ,oCAAoC,MAAM,cAAc;;;;;;;KCChE,iBAAiB;KAEjB;EACV;;EAEA;;EAEA;;EAEA;;;;;;EAMA;;;;;EAKA;;cAGW,uBAAoB,IAAQ,mBAAiB;;;cCR7C,uBAAoB,OAAW,eAAa;cAG5C,qBAAkB,IAAQ,mBAAiB;;cAI3C,uBAAoB,IAAQ;cAG5B,yBAAsB,wBAA0B;;cAIhD,qBAAkB,IAAQ,yCAAc,6BAAA;;;;;;;;;cASxC,+BAA4B,OAAW;;cAUvC,mBAAgB,IAAQ,mBAAiB;cAGzC,6BAAwB,UAAA,WAAA,sBAAA,cAAA;EAOnC;EACA;EACA;EACA,cAAc;EACd;MACE;;;;;;cAkBS,0BAAuB,IAAQ,gBAAc,sBAAsB;cAenE,gBAAa,aAAiB;EAavC;EACA;EACA,UAfuC;EAgBvC;EACA;EAEA;;;;;EAMA;;eAVQ;;;;;;;;;;;;;;;;;cC/GC,6BAA0B,IACjC,gBAAc,iBACH,WACJ,eACV;;;;;;cAeU,kCAA+B,IACtC,gBAAc,oBAEjB;;;;;;cAaU,+BAA4B,IACnC,gBAAc,WACP,YAAU,6BAEpB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,68 +1,200 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Instruction, Transaction, TransactionMessageBytesBase64 } from "@solana/kit";
|
|
2
|
+
//#region src/utils/chains.d.ts
|
|
3
3
|
declare const SOLANA_CHAINS: readonly ["solana:mainnet", "solana:devnet", "solana:testnet", "solana:localnet"];
|
|
4
4
|
type SolanaChainId = (typeof SOLANA_CHAINS)[number];
|
|
5
|
-
declare const getSolNetworkId: (chain: SolanaChainId) => "solana-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
declare const getSolNetworkId: (chain: SolanaChainId) => "solana-devnet" | "solana-localnet" | "solana-mainnet" | "solana-testnet";
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/utils/offchainMessage.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Wraps a raw message in the off-chain message envelope that hardware wallets sign.
|
|
10
|
+
* Returns `null` if the message cannot be wrapped (binary content, empty, or too long).
|
|
11
|
+
*/
|
|
12
|
+
declare const serializeOffchainMessage: (message: Uint8Array, signerPublicKey: Uint8Array) => Uint8Array | null;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region ../../node_modules/.pnpm/@solana+nominal-types@6.10.0_typescript@7.0.2/node_modules/@solana/nominal-types/dist/types/index.d.ts
|
|
15
|
+
type StringEncoding = 'base58' | 'base64';
|
|
16
|
+
/**
|
|
17
|
+
* Use this to produce a new type that satisfies the original type, but not the other way around.
|
|
18
|
+
* That is to say, the branded type is acceptable wherever the original type is specified, but
|
|
19
|
+
* wherever the branded type is specified, the original type will be insufficient.
|
|
20
|
+
*
|
|
21
|
+
* You can use this to create specialized instances of strings, numbers, objects, and more which
|
|
22
|
+
* you would like to assert are special in some way (eg. numbers that are non-negative, strings
|
|
23
|
+
* which represent the names of foods, objects that have passed validation).
|
|
24
|
+
*
|
|
25
|
+
* @typeParam T - The base type to brand
|
|
26
|
+
* @typeParam TBrandName - A string that identifies a particular brand. Branded types with identical
|
|
27
|
+
* names will satisfy each other so long as their base types satisfy each other. Branded types with
|
|
28
|
+
* different names will never satisfy each other.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const unverifiedName = 'Alice';
|
|
33
|
+
* const verifiedName = unverifiedName as Brand<'Alice', 'VerifiedName'>;
|
|
34
|
+
*
|
|
35
|
+
* 'Alice' satisfies Brand<string, 'VerifiedName'>; // ERROR
|
|
36
|
+
* 'Alice' satisfies Brand<'Alice', 'VerifiedName'>; // ERROR
|
|
37
|
+
* unverifiedName satisfies Brand<string, 'VerifiedName'>; // ERROR
|
|
38
|
+
* verifiedName satisfies Brand<'Bob', 'VerifiedName'>; // ERROR
|
|
39
|
+
* verifiedName satisfies Brand<'Alice', 'VerifiedName'>; // OK
|
|
40
|
+
* verifiedName satisfies Brand<string, 'VerifiedName'>; // OK
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
type Brand<T, TBrandName extends string> = NominalType<'brand', TBrandName> & T;
|
|
44
|
+
/**
|
|
45
|
+
* Use this to produce a new type that satisfies the original string type, but adds extra type
|
|
46
|
+
* information that marks the string as being encoded in a particular format.
|
|
47
|
+
*
|
|
48
|
+
* @typeParam T - The underlying string type
|
|
49
|
+
* @typeParam TEncoding - The encoding format of the string
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* const untaggedString = 'dv1ZAGvdsz5hHLwWXsVnM94hWf1pjbKVau1QVkaMJ92';
|
|
54
|
+
* const encodedString = untaggedString as EncodedString<typeof untaggedString, 'base58'>;
|
|
55
|
+
*
|
|
56
|
+
* encodedString satisfies EncodedString<'dv1ZAGvdsz5hHLwWXsVnM94hWf1pjbKVau1QVkaMJ92', 'base58'>; // OK
|
|
57
|
+
* encodedString satisfies EncodedString<string, 'base58'>; // OK
|
|
58
|
+
* encodedString satisfies EncodedString<string, 'base64'>; // ERROR
|
|
59
|
+
* untaggedString satisfies EncodedString<string, 'base58'>; // ERROR
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
type EncodedString<T extends string, TEncoding extends StringEncoding> = NominalType<'stringEncoding', TEncoding> & T;
|
|
63
|
+
/**
|
|
64
|
+
* Use this to produce a nominal type.
|
|
65
|
+
*
|
|
66
|
+
* This can be intersected with other base types to produce custom branded types.
|
|
67
|
+
*
|
|
68
|
+
* @typeParam TKey - The name of the nominal type. This distinguishes one nominal type from another.
|
|
69
|
+
* @typeParam TMarker - The type of the value the nominal type can take.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* type SweeteningSubstance = 'aspartame' | 'cane-sugar' | 'stevia';
|
|
74
|
+
* type Sweetener<T extends SweeteningSubstance> = NominalType<'sweetener', T>;
|
|
75
|
+
*
|
|
76
|
+
* // This function accepts sweetened foods, except those with aspartame.
|
|
77
|
+
* declare function eat(food: string & Sweetener<Exclude<SweeteningSubstance, 'aspartame'>>): void;
|
|
78
|
+
*
|
|
79
|
+
* const artificiallySweetenedDessert = 'ice-cream' as string & Sweetener<'aspartame'>;
|
|
80
|
+
* eat(artificiallySweetenedDessert); // ERROR
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
type NominalType<TKey extends string, TMarker extends string> = { readonly [K in `__${TKey}:@solana/kit`]: TMarker; };
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region ../../node_modules/.pnpm/@solana+addresses@6.10.0_fastestsmallesttextencoderdecoder@1.0.22_typescript@7.0.2/node_modules/@solana/addresses/dist/types/address.d.ts
|
|
86
|
+
/**
|
|
87
|
+
* Represents a string that validates as a Solana address. Functions that require well-formed
|
|
88
|
+
* addresses should specify their inputs in terms of this type.
|
|
89
|
+
*
|
|
90
|
+
* Whenever you need to validate an arbitrary string as a base58-encoded address, use the
|
|
91
|
+
* {@link address}, {@link assertIsAddress}, or {@link isAddress} functions in this package.
|
|
92
|
+
*/
|
|
93
|
+
type Address<TAddress extends string = string> = Brand<EncodedString<TAddress, 'base58'>, 'Address'>;
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/utils/transaction.d.ts
|
|
96
|
+
/**
|
|
97
|
+
* A Solana transaction: raw wire message bytes plus a signer-address → signature map.
|
|
98
|
+
* Kit's decoder/encoder handles both legacy and v0 wire formats transparently.
|
|
99
|
+
*/
|
|
100
|
+
type SolTransaction = Transaction;
|
|
101
|
+
type SolTransactionInfo = {
|
|
102
|
+
version: "legacy" | 0 | 1;
|
|
103
|
+
/** compiled lifetime token — the recent blockhash (or nonce for durable-nonce transactions) */
|
|
104
|
+
recentBlockhash: string;
|
|
105
|
+
/** first static account, the account that pays the transaction fee */
|
|
106
|
+
feePayer: string;
|
|
107
|
+
/** all required signer addresses, in wire order */
|
|
108
|
+
signerAddresses: string[];
|
|
109
|
+
/**
|
|
110
|
+
* The account expected to sign in wallet flows.
|
|
111
|
+
* `undefined` when the transaction has several signers (e.g. sponsored/partially-signed
|
|
112
|
+
* dapp transactions) — callers use this to fall back to the dapp-provided address.
|
|
113
|
+
*/
|
|
114
|
+
address: string | undefined;
|
|
115
|
+
/**
|
|
116
|
+
* canonical (fee payer) base58 transaction signature, verified against the message bytes;
|
|
117
|
+
* null when the fee payer hasn't signed
|
|
118
|
+
*/
|
|
119
|
+
signature: string | null;
|
|
18
120
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
declare const
|
|
23
|
-
declare const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
121
|
+
declare const parseTransactionInfo: (tx: SolTransaction) => SolTransactionInfo;
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/utils/serialization.d.ts
|
|
124
|
+
declare const transactionFromBytes: (bytes: Uint8Array) => SolTransaction;
|
|
125
|
+
declare const transactionToBytes: (tx: SolTransaction) => Uint8Array;
|
|
126
|
+
/** base58 of the wire-format transaction — both legacy and v0, wire-compatible with web3.js */
|
|
127
|
+
declare const serializeTransaction: (tx: SolTransaction) => string;
|
|
128
|
+
declare const deserializeTransaction: (transaction: string) => SolTransaction;
|
|
129
|
+
/** decoded compiled message — legacy and v0 wire formats are handled transparently */
|
|
130
|
+
declare const getCompiledMessage: (tx: SolTransaction) => import("@solana/kit").CompiledTransactionMessage & Readonly<{
|
|
131
|
+
lifetimeToken: string;
|
|
132
|
+
}>;
|
|
133
|
+
/**
|
|
134
|
+
* Whether the bytes parse as a complete compiled transaction message (legacy or v0).
|
|
135
|
+
* Wallets must refuse to sign such a payload as a "message": Solana software accounts sign raw
|
|
136
|
+
* message bytes with no domain separator, so the resulting ed25519 signature would double as a
|
|
137
|
+
* valid transaction signature.
|
|
138
|
+
*/
|
|
139
|
+
declare const isCompiledTransactionMessage: (bytes: Uint8Array) => boolean;
|
|
140
|
+
/** base64 of the compiled message bytes, the format `getFeeForMessage` expects */
|
|
141
|
+
declare const getMessageBase64: (tx: SolTransaction) => TransactionMessageBytesBase64;
|
|
142
|
+
declare const buildUnsignedTransaction: ({ feePayer, blockhash, lastValidBlockHeight, instructions, version }: {
|
|
143
|
+
feePayer: string;
|
|
144
|
+
blockhash: string;
|
|
145
|
+
lastValidBlockHeight: bigint;
|
|
146
|
+
instructions: Instruction[];
|
|
147
|
+
version?: "legacy" | 0;
|
|
148
|
+
}) => SolTransaction;
|
|
149
|
+
/**
|
|
150
|
+
* Returns a copy of the transaction with its lifetime token (recent blockhash) replaced,
|
|
151
|
+
* re-encoding the compiled message. Existing signatures are reset to null — changing the
|
|
152
|
+
* blockhash invalidates them.
|
|
153
|
+
*/
|
|
154
|
+
declare const setTransactionBlockhash: (tx: SolTransaction, blockhash: string) => SolTransaction;
|
|
155
|
+
declare const txToHumanJSON: (tx: string | SolTransaction) => {
|
|
156
|
+
version: "legacy" | 0 | 1;
|
|
157
|
+
signatures: (string | null)[];
|
|
158
|
+
feePayer: Address;
|
|
159
|
+
recentBlockhash: string | null;
|
|
160
|
+
staticAccountKeys: readonly string[];
|
|
161
|
+
addressTableLookups: {
|
|
162
|
+
accountKey: string;
|
|
163
|
+
writableIndexes: number[];
|
|
164
|
+
readonlyIndexes: number[];
|
|
165
|
+
}[];
|
|
166
|
+
instructions: {
|
|
167
|
+
programIdIndex: number;
|
|
168
|
+
programId: Address;
|
|
169
|
+
accounts: {
|
|
170
|
+
index: number;
|
|
171
|
+
pubkey: Address;
|
|
172
|
+
isSigner: boolean;
|
|
173
|
+
isWritable: boolean;
|
|
33
174
|
}[];
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
programId: string;
|
|
37
|
-
accounts: {
|
|
38
|
-
index: number;
|
|
39
|
-
pubkey: string;
|
|
40
|
-
}[];
|
|
41
|
-
data: string;
|
|
42
|
-
}[];
|
|
43
|
-
} | {
|
|
44
|
-
type: string;
|
|
45
|
-
signatures: (string | null)[];
|
|
46
|
-
feePayer: string | null;
|
|
47
|
-
recentBlockhash: string | null;
|
|
48
|
-
instructions: {
|
|
49
|
-
programId: string;
|
|
50
|
-
accounts: {
|
|
51
|
-
pubkey: string;
|
|
52
|
-
isSigner: boolean;
|
|
53
|
-
isWritable: boolean;
|
|
54
|
-
}[];
|
|
55
|
-
data: string;
|
|
56
|
-
}[];
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
declare const getKeypair: (secretKey: Uint8Array) => Keypair;
|
|
60
|
-
|
|
61
|
-
declare const isVersionedTransaction: (transaction: Transaction | VersionedTransaction) => transaction is VersionedTransaction;
|
|
62
|
-
declare const parseTransactionInfo: (tx: Transaction | VersionedTransaction) => {
|
|
63
|
-
recentBlockhash: string | undefined;
|
|
64
|
-
address: string | undefined;
|
|
65
|
-
signature: string | null;
|
|
175
|
+
data: string;
|
|
176
|
+
}[];
|
|
66
177
|
};
|
|
67
|
-
|
|
68
|
-
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region src/utils/signing.d.ts
|
|
180
|
+
/**
|
|
181
|
+
* Returns a copy of the transaction with `signature` attached for `address`.
|
|
182
|
+
* Throws if `address` is not a required signer of the transaction (the signatures
|
|
183
|
+
* map is keyed in wire order at decode time — adding a key would corrupt re-encoding).
|
|
184
|
+
*/
|
|
185
|
+
declare const attachTransactionSignature: (tx: SolTransaction, address: string, signature: Uint8Array) => SolTransaction;
|
|
186
|
+
/**
|
|
187
|
+
* Returns the signature attached for `address`, verified against the transaction's message
|
|
188
|
+
* bytes; null when missing, all-zeros, or invalid. Unlike `parseTransactionInfo`, this checks
|
|
189
|
+
* a specific signer's slot, so it works on transactions with co-signers.
|
|
190
|
+
*/
|
|
191
|
+
declare const getVerifiedTransactionSignature: (tx: SolTransaction, address: string) => Uint8Array | null;
|
|
192
|
+
/**
|
|
193
|
+
* Signs the transaction's message bytes with the given ed25519 secret key and
|
|
194
|
+
* attaches the signature. Signing happens with @noble/curves (via @talismn/crypto),
|
|
195
|
+
* not WebCrypto — Ed25519 subtle crypto is too recent for the extension's support matrix.
|
|
196
|
+
*/
|
|
197
|
+
declare const signTransactionWithSecretKey: (tx: SolTransaction, secretKey: Uint8Array, expectedAddress?: string) => SolTransaction;
|
|
198
|
+
//#endregion
|
|
199
|
+
export { SOLANA_CHAINS, SolTransaction, SolTransactionInfo, SolanaChainId, attachTransactionSignature, buildUnsignedTransaction, deserializeTransaction, getCompiledMessage, getMessageBase64, getSolNetworkId, getVerifiedTransactionSignature, isCompiledTransactionMessage, parseTransactionInfo, serializeOffchainMessage, serializeTransaction, setTransactionBlockhash, signTransactionWithSecretKey, transactionFromBytes, transactionToBytes, txToHumanJSON };
|
|
200
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/utils/chains.ts","../src/utils/offchainMessage.ts","../../../node_modules/.pnpm/@solana+nominal-types@6.10.0_typescript@7.0.2/node_modules/@solana/nominal-types/dist/types/index.d.ts","../../../node_modules/.pnpm/@solana+addresses@6.10.0_fastestsmallesttextencoderdecoder@1.0.22_typescript@7.0.2/node_modules/@solana/addresses/dist/types/address.d.ts","../src/utils/transaction.ts","../src/utils/serialization.ts","../src/utils/signing.ts"],"x_google_ignoreList":[2,3],"mappings":";;cAAa;KAOD,wBAAwB;cAEvB,kBAAe,OAAW;;;;;;;cCoC1B,2BAAwB,SAC1B,YAAU,iBACF,eAChB;;;KCzBE;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAiDO,MAAM,GAAG,6BAA6B,qBAAqB,cAAc;;;;;;;;;;;;;;;;;;;KAoCzE,cAAc,kBAAkB,kBAAkB,kBAAkB,8BAA8B,aAAa;;;;;;;;;;;;;;;;;;;;;KAqB/G,YAAY,qBAAqB,sCAC/B,UAAU,qBAAqB;;;;;;;;;;KCzHjC,QAAQ,oCAAoC,MAAM,cAAc;;;;;;;KCChE,iBAAiB;KAEjB;EACV;;EAEA;;EAEA;;EAEA;;;;;;EAMA;;;;;EAKA;;cAGW,uBAAoB,IAAQ,mBAAiB;;;cCR7C,uBAAoB,OAAW,eAAa;cAG5C,qBAAkB,IAAQ,mBAAiB;;cAI3C,uBAAoB,IAAQ;cAG5B,yBAAsB,wBAA0B;;cAIhD,qBAAkB,IAAQ,yCAAc,6BAAA;;;;;;;;;cASxC,+BAA4B,OAAW;;cAUvC,mBAAgB,IAAQ,mBAAiB;cAGzC,6BAAwB,UAAA,WAAA,sBAAA,cAAA;EAOnC;EACA;EACA;EACA,cAAc;EACd;MACE;;;;;;cAkBS,0BAAuB,IAAQ,gBAAc,sBAAsB;cAenE,gBAAa,aAAiB;EAavC;EACA;EACA,UAfuC;EAgBvC;EACA;EAEA;;;;;EAMA;;eAVQ;;;;;;;;;;;;;;;;;cC/GC,6BAA0B,IACjC,gBAAc,iBACH,WACJ,eACV;;;;;;cAeU,kCAA+B,IACtC,gBAAc,oBAEjB;;;;;;cAaU,+BAA4B,IACnC,gBAAc,WACP,YAAU,6BAEpB"}
|