apps/web/lib/solana/record.ts

The wallet signs the launch record. Shown whole, as it was in the repository when this site was built. Line numbers link: add #L12 to the address.

apps/web/lib/solana/record.ts28 lines
1// Client side of the launch record: the wallet signs launchRecordText(record, collectionName) (ed25519 signMessage).2// In fake mode without a connected wallet, a throwaway in-browser Ed25519 key (WebCrypto) signs instead, so the whole3// flow runs in a plain dev browser; the server accepts that only for FAKE mints outside production.4import { base58Encode } from '@solary/core/pump';5import { launchRecordBytes, type LaunchRecord } from '@solary/core/launch';6import type { SolanaWalletLike } from './types';7 8export async function signLaunchRecord(record: LaunchRecord, collectionName: string, wallet: Pick<SolanaWalletLike, 'signMessage'>): Promise<string> {9  const sig = await wallet.signMessage(launchRecordBytes(record, collectionName));10  return base58Encode(sig);11}12 13/** A throwaway Ed25519 signer (dev fake mode only). */14export async function devWallet(): Promise<Pick<SolanaWalletLike, 'publicKey' | 'signMessage'>> {15  const subtle = globalThis.crypto?.subtle;16  if (!subtle) throw new Error('This browser has no WebCrypto. Connect a Solana wallet instead.');17  let kp: CryptoKeyPair;18  try {19    kp = (await subtle.generateKey({ name: 'Ed25519' }, false, ['sign', 'verify'])) as CryptoKeyPair;20  } catch {21    throw new Error('This browser cannot make a test key (Ed25519). Connect a Solana wallet instead.');22  }23  const raw = new Uint8Array(await subtle.exportKey('raw', kp.publicKey));24  return {25    publicKey: base58Encode(raw),26    signMessage: async (m: Uint8Array) => new Uint8Array(await subtle.sign({ name: 'Ed25519' }, kp.privateKey, m as BufferSource)),27  };28}