diff --git a/Cargo.lock b/Cargo.lock index 0f1f068..805630a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1375,9 +1375,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.103.15" +version = "0.103.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2" +checksum = "4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281" dependencies = [ "ring", "rustls-pki-types", @@ -2791,9 +2791,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "1.0.1" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8782dd5a41a24eed3a4f40b606249b3e236ca61adf1f25ea4d45c73de122b502" +checksum = "f5f280bbb2b287bc8e7de7e3852945a0ff50d1bbcb5ed42b6c7a568c546df171" dependencies = [ "rustls-pki-types", ] @@ -3074,9 +3074,9 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.13+zstd.1.5.6" +version = "2.1.2+zstd.1.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38ff0f21cfee8f97d94cef41359e0c89aa6113028ab0291aa8ca0038995a95aa" +checksum = "481ada9c543b2323cbb7bbdbb5249177fbf0188ed959ed2c15e4b22421c84ed3" dependencies = [ "cc", "pkg-config", diff --git a/Makefile b/Makefile index a39df67..3b5ae68 100644 --- a/Makefile +++ b/Makefile @@ -20,8 +20,13 @@ solana-cli-version: cargo-nightly: cargo $(nightly) $(ARGS) +# zstd 0.13 is pinned by solana-account-decoder-client-types (via solana-rpc-client) +# Fixing requires zstd 0.14 / zstd-safe 8.x, which no Solana release depends on yet. audit: - cargo audit $(ARGS) + cargo audit \ + --ignore RUSTSEC-2026-0391 \ + --ignore RUSTSEC-2026-0403 \ + $(ARGS) spellcheck: cargo spellcheck --code 1 $(ARGS) diff --git a/clients/js/src/assertValidTransferSolDestination.ts b/clients/js/src/assertValidTransferSolDestination.ts index b92b518..b4c5d3f 100644 --- a/clients/js/src/assertValidTransferSolDestination.ts +++ b/clients/js/src/assertValidTransferSolDestination.ts @@ -13,21 +13,27 @@ import { import { SYSTEM_PROGRAM_ADDRESS } from './generated'; +/** Details of why a destination was rejected by {@link assertValidTransferSolDestination}. */ +export type InvalidTransferSolDestinationDetails = + | { + reason: 'unexpected-owner'; + /** The program that owns the destination account. */ + owner: Address; + } + | { reason: 'unfunded-recipient' } + | { reason: 'off-curve' }; + /** Distinguishes why a destination was rejected by {@link assertValidTransferSolDestination}. */ -export type InvalidTransferSolDestinationReason = 'unexpected-owner' | 'unfunded-recipient' | 'off-curve'; +export type InvalidTransferSolDestinationReason = InvalidTransferSolDestinationDetails['reason']; -/** - * Thrown by {@link assertValidTransferSolDestination} when a destination is rejected. `owner` is set only - * when `reason` is `'unexpected-owner'`. - */ +/** Thrown by {@link assertValidTransferSolDestination} when a destination is rejected. */ export class InvalidTransferSolDestinationError extends Error { override readonly name = 'InvalidTransferSolDestinationError'; constructor( message: string, readonly destination: Address, - readonly reason: InvalidTransferSolDestinationReason, - readonly owner?: Address, + readonly details: InvalidTransferSolDestinationDetails, ) { super(message); } @@ -46,7 +52,7 @@ export type AssertValidTransferSolDestinationConfig = FetchAccountConfig & { /** * Allow an off-curve (program-derived) destination, existing or not. Defaults to `true`, since * program-controlled wallets such as multisigs are common, legitimate recipients; set to `false` to - * reject off-curve destinations until the recipient confirms they control them. + * reject off-curve destinations. */ allowOffCurve?: boolean; /** @@ -64,8 +70,8 @@ export type AssertValidTransferSolDestinationConfig = FetchAccountConfig & { * default), e.g. an SPL token mint. SOL sent to such an account is typically unrecoverable. * - `'unfunded-recipient'`: no account exists, which often means a mistyped address. Skipped when * `allowUnfundedRecipient` is set. - * - `'off-curve'`: the address is off-curve, existing or not, and may be a smart wallet the recipient - * must confirm they control. Only checked when `allowOffCurve` is `false`. + * - `'off-curve'`: the address is off-curve, existing or not. Only checked when `allowOffCurve` is + * `false`. * * The owner is checked first, so an off-curve account owned by another program, such as an associated * token account, reports `'unexpected-owner'`. @@ -89,23 +95,22 @@ export async function assertValidTransferSolDestination( throw new InvalidTransferSolDestinationError( `Refusing to transfer SOL to ${destination}: it is owned by program ${account.programAddress}, not the expected program (${programOwner}).`, destination, - 'unexpected-owner', - account.programAddress, + { reason: 'unexpected-owner', owner: account.programAddress }, ); } } else if (!allowUnfundedRecipient) { throw new InvalidTransferSolDestinationError( `Refusing to transfer SOL to ${destination}: it has no account on-chain yet, which often means the address is mistyped. If you intend to fund a new account, pass { allowUnfundedRecipient: true }.`, destination, - 'unfunded-recipient', + { reason: 'unfunded-recipient' }, ); } - if (isOffCurveAddress(destination) && !allowOffCurve) { + if (!allowOffCurve && isOffCurveAddress(destination)) { throw new InvalidTransferSolDestinationError( - `Refusing to transfer SOL to ${destination}: it is an off-curve (program-derived) address, which no keypair controls. It may be a program-controlled account such as a multisig or smart wallet; once the recipient confirms they control it, pass { allowOffCurve: true }.`, + `Refusing to transfer SOL to ${destination}: it is an off-curve (program-derived) address, which no keypair controls. It may be a program-controlled account such as a multisig or smart wallet; to allow it, pass { allowOffCurve: true }.`, destination, - 'off-curve', + { reason: 'off-curve' }, ); } } diff --git a/clients/js/test/assertValidTransferSolDestination.test.ts b/clients/js/test/assertValidTransferSolDestination.test.ts index 97fc17f..c5cc6db 100644 --- a/clients/js/test/assertValidTransferSolDestination.test.ts +++ b/clients/js/test/assertValidTransferSolDestination.test.ts @@ -61,8 +61,7 @@ it('rejects an existing destination owned by another program', async () => { await expect(promise).rejects.toMatchObject({ message: expect.stringContaining(`owned by program ${TOKEN_PROGRAM_ADDRESS}`), destination, - reason: 'unexpected-owner', - owner: TOKEN_PROGRAM_ADDRESS, + details: { reason: 'unexpected-owner', owner: TOKEN_PROGRAM_ADDRESS }, }); }); @@ -85,7 +84,7 @@ it('rejects a System-Program-owned destination when programOwner expects another // Then it is rejected when the Token program is the expected owner. await expect( assertValidTransferSolDestination(client.rpc, destination, { programOwner: TOKEN_PROGRAM_ADDRESS }), - ).rejects.toMatchObject({ reason: 'unexpected-owner', owner: SYSTEM_PROGRAM_ADDRESS }); + ).rejects.toMatchObject({ details: { reason: 'unexpected-owner', owner: SYSTEM_PROGRAM_ADDRESS } }); }); it('accepts a HasAddress destination', async () => { @@ -109,7 +108,7 @@ it('rejects a HasAddress destination owned by another program', async () => { // Then it is rejected, reporting the wrapped address. await expect(assertValidTransferSolDestination(client.rpc, destination)).rejects.toMatchObject({ destination: destination.address, - reason: 'unexpected-owner', + details: { reason: 'unexpected-owner' }, }); }); @@ -126,7 +125,7 @@ it('accepts a ProgramDerivedAddress destination', async () => { await expect(assertValidTransferSolDestination(client.rpc, destination)).resolves.toBeUndefined(); await expect( assertValidTransferSolDestination(client.rpc, destination, { allowOffCurve: false }), - ).rejects.toMatchObject({ destination: destination[0], reason: 'off-curve' }); + ).rejects.toMatchObject({ destination: destination[0], details: { reason: 'off-curve' } }); }); it('rejects an unfunded recipient by default', async () => { @@ -136,7 +135,7 @@ it('rejects an unfunded recipient by default', async () => { // Then it is rejected as unfunded. await expect(assertValidTransferSolDestination(client.rpc, destination)).rejects.toMatchObject({ - reason: 'unfunded-recipient', + details: { reason: 'unfunded-recipient' }, }); }); @@ -173,7 +172,7 @@ it('rejects an unfunded off-curve recipient as off-curve when allowOffCurve is f allowOffCurve: false, allowUnfundedRecipient: true, }), - ).rejects.toMatchObject({ reason: 'off-curve' }); + ).rejects.toMatchObject({ details: { reason: 'off-curve' } }); }); it('accepts an existing off-curve System-Program-owned account unless allowOffCurve is false', async () => { @@ -186,7 +185,7 @@ it('accepts an existing off-curve System-Program-owned account unless allowOffCu await expect(assertValidTransferSolDestination(client.rpc, destination)).resolves.toBeUndefined(); await expect( assertValidTransferSolDestination(client.rpc, destination, { allowOffCurve: false }), - ).rejects.toMatchObject({ reason: 'off-curve' }); + ).rejects.toMatchObject({ details: { reason: 'off-curve' } }); }); it('does not forward guard options to getAccountInfo', async () => {