/** * Soroban authorization-entry payload helpers + the flat `Signatures` map codec. * * These are thin wrappers over the stellar-sdk's native Protocol-27 auth * primitives (`buildAuthorizationEntryPreimage`). The old kit hand-rolled a * stack of "does this SDK support P27?" probe shims; on stellar-sdk >= 16 those * are all dead, so this module simply uses the SDK. * * The smart wallet's `__check_auth` reads a `Signatures` value — a single * `Map` — from the address credentials. Each signer * contributes one entry keyed by its on-chain `SignerKey`. The host rejects an * `ScMap` whose keys are not in the host's canonical sort order, so the map is * sorted with {@link compareScVal} (NOT a byte/`localeCompare` sort — see below). * * @packageDocumentation */ import { xdr } from "@stellar/stellar-sdk"; import type { Spec as ContractSpec } from "@stellar/stellar-sdk/contract"; import type { Signature as SDKSignature, SignerKey as SDKSignerKey } from "passkey-kit-sdk"; /** * Extract the {@link xdr.SorobanAddressCredentials} from a credentials union, * for the address / addressV2 / addressWithDelegates variants. * * @throws {SigningError} If the credentials are not address-based. */ export declare function getAddressCredentials(credentials: xdr.SorobanCredentials): xdr.SorobanAddressCredentials; /** * Whether a credentials union uses an address-bound signature payload (the P27 * V2 / with-delegates variants), whose preimage binds the invoker address. */ export declare function usesAddressBoundPayload(credentials: xdr.SorobanCredentials): boolean; /** * Coerce a credentials union to an address-bound variant (CAP-0071-02). * * Legacy V1 `sorobanCredentialsAddress` credentials are upgraded to * `sorobanCredentialsAddressV2` IN PLACE of the signed payload's semantics: the * V2 preimage (`HashIdPreimageSorobanAuthorizationWithAddress`) binds the * authorizing address into the hash the signer signs, so the same signer key on * two different wallets can never produce interchangeable signatures. V1's * preimage has no address field — signing it verbatim would produce a payload * that is identical across wallets for a signer key installed on more than * one wallet. * * Already-address-bound variants (V2, with-delegates) pass through unchanged. * * @throws {SigningError} If the credentials are not address-based. */ export declare function toAddressBoundCredentials(credentials: xdr.SorobanCredentials): xdr.SorobanCredentials; /** * Assert that a signature-expiration ledger is a valid `u32`. * * @throws {SigningError} If not a `u32` integer. */ export declare function assertSignatureExpirationLedger(expiration: number): void; /** * Build the signature payload (the 32-byte hash a signer signs) for an * authorization entry at a given expiration ledger. * * Sets the expiration on the entry's address credentials, then hashes the SDK's * canonical authorization-entry preimage. Works for the address, addressV2, and * addressWithDelegates credential variants. * * @throws {SigningError} If `expiration` is not a valid `u32`. */ export declare function buildSignaturePayload(networkPassphrase: string, entry: xdr.SorobanAuthorizationEntry, expiration: number): Buffer; /** * Compare two ScVals in the order the Soroban host uses when it validates that * an ScMap is sorted by key (host `metered_map::from_map`, which rejects an * unsorted map with `InvalidInput`). * * This is deliberately NOT a comparison of the XDR byte encodings. XDR prefixes * every variable-length payload (Bytes, Symbol, String, Vec) with a 4-byte * length, so `toXDR("hex")` sorting is length-major; the host instead compares * those payloads element-wise by content (Rust slice `Ord`), where a shorter * value that is a prefix of a longer one sorts first. The old kit's * `localeCompare` on a symbol+hex string approximated this and could diverge * from the host, producing a map the wallet rejects at `__check_auth`. * * Only the shapes that appear as `SignerKey` map keys are handled precisely * (Vec, Symbol, String, Bytes, Address). All other shapes are same-type here * (the discriminant is compared first), so their fixed-width XDR encodings sort * order-equivalently to the host. */ export declare function compareScVal(a: xdr.ScVal, b: xdr.ScVal): number; /** The `SignerVal` UDT type def, for decoding a stored signer entry's value. */ export declare const SIGNER_VAL_UDT: xdr.ScSpecTypeDef; /** Encode a native `SignerKey` union into its contract ScVal via the spec. */ export declare function signerKeyToScVal(spec: ContractSpec, key: SDKSignerKey): xdr.ScVal; /** * Encode a native `Signature` union into its contract ScVal via the spec, or * `scvVoid` when there is no signature value (policy signers). */ export declare function signatureToScVal(spec: ContractSpec, val: SDKSignature | undefined): xdr.ScVal; /** * Upsert a `(SignerKey, Signature)` pair into the entry's `Signatures` value, * which is encoded as `scvVec([ scvMap([...]) ])`. * * A signer key already present in the map is replaced (co-signing is idempotent * per signer). The map is re-sorted by key in host order after every insert, so * the wallet's `__check_auth` accepts it. * * @throws {SigningError} If the existing signature is neither void nor a * Signatures vec. */ export declare function upsertSignatureEntry(credentials: xdr.SorobanAddressCredentials, scKey: xdr.ScVal, scVal: xdr.ScVal): void; //# sourceMappingURL=auth-payload.d.ts.map