@unicitylabs/sphere-sdk 0.9.0-dev.0 → 0.9.1-dev.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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../token-engine/sdk.ts","../../token-engine/identity.ts","../../core/errors.ts","../../core/logger.ts","../../token-engine/SpherePaymentData.ts","../../token-engine/token-blob.ts","../../token-engine/SphereTokenEngine.ts","../../token-engine/factory.ts","../../token-engine/unicity-id.ts"],"sourcesContent":["/**\n * token-engine/sdk.ts — the SINGLE place that imports @unicitylabs/state-transition-sdk.\n *\n * The v1 cut-over is done: the canonical package name now resolves to the v2 SDK\n * (the migration-era `state-transition-sdk-v2` npm alias is gone, and v1 with it).\n *\n * Everything else in token-engine/ imports SDK symbols from `./sdk`, never from the package directly.\n * ESLint `no-restricted-imports` forbids importing the SDK anywhere except this file.\n *\n * Import path note: subpaths are `…/lib/<path>.js` (no `/src/`); no root barrel.\n */\n\n// ── client / aggregator / proof / network / trust base ──────────────────────\nexport { StateTransitionClient } from '@unicitylabs/state-transition-sdk/lib/StateTransitionClient.js';\nexport { AggregatorClient } from '@unicitylabs/state-transition-sdk/lib/api/AggregatorClient.js';\nexport type { IAggregatorClient } from '@unicitylabs/state-transition-sdk/lib/api/IAggregatorClient.js';\nexport { NetworkId } from '@unicitylabs/state-transition-sdk/lib/api/NetworkId.js';\nexport { CertificationData } from '@unicitylabs/state-transition-sdk/lib/api/CertificationData.js';\nexport { CertificationResponse, CertificationStatus } from '@unicitylabs/state-transition-sdk/lib/api/CertificationResponse.js';\nexport { StateId } from '@unicitylabs/state-transition-sdk/lib/api/StateId.js';\nexport { InclusionProof } from '@unicitylabs/state-transition-sdk/lib/api/InclusionProof.js';\nexport { InclusionProofResponse } from '@unicitylabs/state-transition-sdk/lib/api/InclusionProofResponse.js';\nexport { RootTrustBase } from '@unicitylabs/state-transition-sdk/lib/api/bft/RootTrustBase.js';\nexport { waitInclusionProof } from '@unicitylabs/state-transition-sdk/lib/util/InclusionProofUtils.js';\n\n// ── token / transactions ────────────────────────────────────────────────────\nexport { Token } from '@unicitylabs/state-transition-sdk/lib/transaction/Token.js';\nexport { MintTransaction } from '@unicitylabs/state-transition-sdk/lib/transaction/MintTransaction.js';\nexport { TransferTransaction } from '@unicitylabs/state-transition-sdk/lib/transaction/TransferTransaction.js';\nexport { CertifiedMintTransaction } from '@unicitylabs/state-transition-sdk/lib/transaction/CertifiedMintTransaction.js';\nexport { CertifiedTransferTransaction } from '@unicitylabs/state-transition-sdk/lib/transaction/CertifiedTransferTransaction.js';\nexport { TokenId } from '@unicitylabs/state-transition-sdk/lib/transaction/TokenId.js';\nexport { TokenType } from '@unicitylabs/state-transition-sdk/lib/transaction/TokenType.js';\nexport { TokenSalt } from '@unicitylabs/state-transition-sdk/lib/transaction/TokenSalt.js';\nexport type { ITransaction } from '@unicitylabs/state-transition-sdk/lib/transaction/ITransaction.js';\nexport { MintJustificationVerifierService } from '@unicitylabs/state-transition-sdk/lib/transaction/verification/MintJustificationVerifierService.js';\n\n// ── predicates / unlock scripts ─────────────────────────────────────────────\nexport type { IPredicate } from '@unicitylabs/state-transition-sdk/lib/predicate/IPredicate.js';\nexport type { IUnlockScript } from '@unicitylabs/state-transition-sdk/lib/predicate/IUnlockScript.js';\nexport { EncodedPredicate } from '@unicitylabs/state-transition-sdk/lib/predicate/EncodedPredicate.js';\nexport { SignaturePredicate } from '@unicitylabs/state-transition-sdk/lib/predicate/builtin/SignaturePredicate.js';\nexport { SignaturePredicateUnlockScript } from '@unicitylabs/state-transition-sdk/lib/predicate/builtin/SignaturePredicateUnlockScript.js';\nexport { BurnPredicate } from '@unicitylabs/state-transition-sdk/lib/predicate/builtin/BurnPredicate.js';\nexport { PredicateVerifierService } from '@unicitylabs/state-transition-sdk/lib/predicate/verification/PredicateVerifierService.js';\n\n// ── crypto / hashing ────────────────────────────────────────────────────────\nexport { SigningService } from '@unicitylabs/state-transition-sdk/lib/crypto/secp256k1/SigningService.js';\nexport { Signature } from '@unicitylabs/state-transition-sdk/lib/crypto/secp256k1/Signature.js';\nexport { MintSigningService } from '@unicitylabs/state-transition-sdk/lib/crypto/MintSigningService.js';\nexport { HashAlgorithm } from '@unicitylabs/state-transition-sdk/lib/crypto/hash/HashAlgorithm.js';\nexport { DataHash } from '@unicitylabs/state-transition-sdk/lib/crypto/hash/DataHash.js';\nexport { DataHasher } from '@unicitylabs/state-transition-sdk/lib/crypto/hash/DataHasher.js';\nexport { DataHasherFactory } from '@unicitylabs/state-transition-sdk/lib/crypto/hash/DataHasherFactory.js';\n\n// ── CBOR serialization ──────────────────────────────────────────────────────\nexport { CborSerializer } from '@unicitylabs/state-transition-sdk/lib/serialization/cbor/CborSerializer.js';\nexport { CborDeserializer } from '@unicitylabs/state-transition-sdk/lib/serialization/cbor/CborDeserializer.js';\nexport { CborError } from '@unicitylabs/state-transition-sdk/lib/serialization/cbor/CborError.js';\n\n// ── payment / value / split ─────────────────────────────────────────────────\nexport type { IPaymentData } from '@unicitylabs/state-transition-sdk/lib/payment/IPaymentData.js';\nexport { Asset } from '@unicitylabs/state-transition-sdk/lib/payment/asset/Asset.js';\nexport { AssetId } from '@unicitylabs/state-transition-sdk/lib/payment/asset/AssetId.js';\nexport { PaymentAssetCollection } from '@unicitylabs/state-transition-sdk/lib/payment/asset/PaymentAssetCollection.js';\nexport { TokenSplit } from '@unicitylabs/state-transition-sdk/lib/payment/TokenSplit.js';\nexport { SplitTokenRequest } from '@unicitylabs/state-transition-sdk/lib/payment/SplitTokenRequest.js';\nexport { SplitToken } from '@unicitylabs/state-transition-sdk/lib/payment/SplitToken.js';\nexport { SplitAssetProof } from '@unicitylabs/state-transition-sdk/lib/payment/SplitAssetProof.js';\nexport { SplitMintJustification } from '@unicitylabs/state-transition-sdk/lib/payment/SplitMintJustification.js';\nexport { SplitMintJustificationVerifier } from '@unicitylabs/state-transition-sdk/lib/payment/SplitMintJustificationVerifier.js';\n\n// ── verification result types ───────────────────────────────────────────────\nexport { VerificationStatus } from '@unicitylabs/state-transition-sdk/lib/verification/VerificationStatus.js';\nexport { VerificationResult } from '@unicitylabs/state-transition-sdk/lib/verification/VerificationResult.js';\n\n// ── unicity-id (nametag) ────────────────────────────────────────────────────\nexport { UnicityId } from '@unicitylabs/state-transition-sdk/lib/unicity-id/UnicityId.js';\nexport { UnicityIdMintTransaction } from '@unicitylabs/state-transition-sdk/lib/unicity-id/UnicityIdMintTransaction.js';\nexport { CertifiedUnicityIdMintTransaction } from '@unicitylabs/state-transition-sdk/lib/unicity-id/CertifiedUnicityIdMintTransaction.js';\nexport { UnicityIdToken } from '@unicitylabs/state-transition-sdk/lib/unicity-id/UnicityIdToken.js';\n\n// ── util ────────────────────────────────────────────────────────────────────\nexport { HexConverter } from '@unicitylabs/state-transition-sdk/lib/util/HexConverter.js';\nexport { BigintConverter } from '@unicitylabs/state-transition-sdk/lib/util/BigintConverter.js';\nexport { BitString } from '@unicitylabs/state-transition-sdk/lib/util/BitString.js';\n","/**\n * token-engine/identity.ts — legacy `DIRECT://` identity address (Path A, A6).\n *\n * Reproduces the wallet's stable L3 identity address EXACTLY as the v1\n * `UnmaskedPredicateReference` → `DirectAddress` path did, but VENDORED (no v1 SDK\n * import) so the v1 dependency can be removed at the final cut-over. Quest XP is\n * keyed on this address, so it MUST stay byte-identical — the multi-vector\n * golden test (identity.test.ts) locks it.\n *\n * The recipe (recovered from v1 `UnmaskedPredicateReference.create` + `DirectAddress.create`):\n * ref = SHA-256( CBOR[ bstr([UNMASKED]), bstr(tokenType.toCBOR()),\n * tstr(\"secp256k1\"), uint(SHA256), bstr(publicKey) ] )\n * imprint = 0x0000 ‖ ref (SHA-256 DataHash imprint)\n * address = \"DIRECT://\" ‖ hex(imprint) ‖ hex( SHA-256(imprint)[0:4] )\n *\n * The CBOR + SHA-256 are standard, so v2's CborSerializer/DataHasher produce\n * byte-identical output; the v1 enum values (UNMASKED=0, HashAlgorithm.SHA256=0)\n * and the SHA-256 imprint prefix (0x0000) are pinned as constants.\n */\n\nimport { CborSerializer, DataHasher, HashAlgorithm, HexConverter } from './sdk';\n\n/**\n * Unicity L3 token type used for identity-address derivation (immutable).\n * Also pinned as the fixed token type of self-issued Unicity ID tokens\n * (token-engine/unicity-id.ts) — the same constant the v1 nametag mint used,\n * keeping the mint deterministic per (name, wallet key).\n */\nexport const UNICITY_TOKEN_TYPE_HEX = 'f8aa13834268d29355ff12183066f0cb902003629bbc5eb9ef0efbe397867509';\n/** v1 `SigningService.algorithm` for secp256k1. */\nconst SIGNING_ALGORITHM = 'secp256k1';\n/** v1 `EmbeddedPredicateType.UNMASKED`. */\nconst EMBEDDED_PREDICATE_UNMASKED = 0;\n/** v1 `HashAlgorithm.SHA256` (as encoded in the reference CBOR). */\nconst HASH_ALGORITHM_SHA256 = 0n;\n/** v1 SHA-256 `DataHash` imprint algorithm tag (2-byte big-endian). */\nconst SHA256_IMPRINT_PREFIX = new Uint8Array([0x00, 0x00]);\n\nfunction hexToBytes(hex: string): Uint8Array {\n const bytes = new Uint8Array(hex.length / 2);\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);\n }\n return bytes;\n}\n\nfunction sha256(data: Uint8Array): Promise<Uint8Array> {\n return new DataHasher(HashAlgorithm.SHA256)\n .update(data)\n .digest()\n .then((h) => h.data);\n}\n\n/**\n * Derive the legacy `DIRECT://` identity address for a compressed (33-byte)\n * secp256k1 public key. Deterministic; byte-identical to the v1 path (Path A).\n */\nexport async function deriveDirectAddress(publicKey: Uint8Array): Promise<string> {\n const tokenTypeCbor = CborSerializer.encodeByteString(hexToBytes(UNICITY_TOKEN_TYPE_HEX)); // v1 TokenType.toCBOR()\n const reference = CborSerializer.encodeArray(\n CborSerializer.encodeByteString(new Uint8Array([EMBEDDED_PREDICATE_UNMASKED])),\n CborSerializer.encodeByteString(tokenTypeCbor),\n CborSerializer.encodeTextString(SIGNING_ALGORITHM),\n CborSerializer.encodeUnsignedInteger(HASH_ALGORITHM_SHA256),\n CborSerializer.encodeByteString(publicKey),\n );\n\n const refHash = await sha256(reference);\n const imprint = new Uint8Array([...SHA256_IMPRINT_PREFIX, ...refHash]);\n const checksum = (await sha256(imprint)).slice(0, 4);\n\n return `DIRECT://${HexConverter.encode(imprint)}${HexConverter.encode(checksum)}`;\n}\n","/**\n * SDK Error Types\n *\n * Structured error codes for programmatic error handling in UI.\n * UI can switch on error.code to show appropriate user-facing messages.\n *\n * @example\n * ```ts\n * import { SphereError } from '@unicitylabs/sphere-sdk';\n *\n * try {\n * await sphere.payments.send({ ... });\n * } catch (err) {\n * if (err instanceof SphereError) {\n * switch (err.code) {\n * case 'INSUFFICIENT_BALANCE': showToast('Not enough funds'); break;\n * case 'INVALID_RECIPIENT': showToast('Recipient not found'); break;\n * case 'TRANSPORT_ERROR': showToast('Network connection issue'); break;\n * case 'TIMEOUT': showToast('Request timed out, try again'); break;\n * default: showToast(err.message);\n * }\n * }\n * }\n * ```\n */\n\nexport type SphereErrorCode =\n | 'NOT_INITIALIZED'\n | 'ALREADY_INITIALIZED'\n | 'INVALID_CONFIG'\n | 'INVALID_IDENTITY'\n | 'INSUFFICIENT_BALANCE'\n | 'INVALID_RECIPIENT'\n | 'TRANSFER_FAILED'\n | 'STORAGE_ERROR'\n | 'TRANSPORT_ERROR'\n | 'AGGREGATOR_ERROR'\n | 'VALIDATION_ERROR'\n | 'NETWORK_ERROR'\n | 'TIMEOUT'\n | 'DECRYPTION_ERROR'\n | 'MODULE_NOT_AVAILABLE'\n | 'SIGNING_ERROR'\n // Token Spend Queue error codes\n | 'SEND_QUEUE_TIMEOUT'\n | 'SEND_INSUFFICIENT_BALANCE'\n | 'SEND_RESERVATION_CANCELLED'\n | 'SEND_QUEUE_FULL'\n | 'MODULE_DESTROYED'\n | 'REENTRANT_GATE'\n // Invoice / Accounting error codes\n | 'INVOICE_NO_TARGETS'\n | 'INVOICE_INVALID_ADDRESS'\n | 'INVOICE_NO_ASSETS'\n | 'INVOICE_INVALID_ASSET'\n | 'INVOICE_INVALID_AMOUNT'\n | 'INVOICE_INVALID_COIN'\n | 'INVOICE_INVALID_NFT'\n | 'INVOICE_PAST_DUE_DATE'\n | 'INVOICE_DUPLICATE_ADDRESS'\n | 'INVOICE_DUPLICATE_COIN'\n | 'INVOICE_DUPLICATE_NFT'\n | 'INVOICE_MINT_FAILED'\n | 'INVOICE_INVALID_PROOF'\n | 'INVOICE_WRONG_TOKEN_TYPE'\n | 'INVOICE_INVALID_DATA'\n | 'INVOICE_ALREADY_EXISTS'\n | 'INVOICE_NOT_FOUND'\n | 'INVOICE_NOT_TARGET'\n | 'INVOICE_ALREADY_CLOSED'\n | 'INVOICE_ALREADY_CANCELLED'\n | 'INVOICE_ORACLE_REQUIRED'\n | 'INVOICE_TERMINATED'\n | 'INVOICE_INVALID_TARGET'\n | 'INVOICE_INVALID_ASSET_INDEX'\n | 'INVOICE_RETURN_EXCEEDS_BALANCE'\n | 'INVOICE_INVALID_DELIVERY_METHOD'\n | 'INVOICE_INVALID_REFUND_ADDRESS'\n | 'INVOICE_INVALID_CONTACT'\n | 'INVOICE_INVALID_ID'\n | 'INVOICE_TOO_MANY_TARGETS'\n | 'INVOICE_TOO_MANY_ASSETS'\n | 'INVOICE_MEMO_TOO_LONG'\n | 'INVOICE_TERMS_TOO_LARGE'\n | 'INVOICE_NOT_TERMINATED'\n | 'INVOICE_NOT_CANCELLED'\n | 'INVOICE_STORAGE_FAILED'\n | 'RATE_LIMITED'\n | 'COMMUNICATIONS_UNAVAILABLE'\n // Swap error codes\n | 'SWAP_INVALID_DEAL'\n | 'SWAP_INVALID_MANIFEST'\n | 'SWAP_NOT_FOUND'\n | 'SWAP_WRONG_STATE'\n | 'SWAP_RESOLVE_FAILED'\n | 'SWAP_DM_SEND_FAILED'\n | 'SWAP_ESCROW_REJECTED'\n | 'SWAP_DEPOSIT_FAILED'\n | 'SWAP_PAYOUT_VERIFICATION_FAILED'\n | 'SWAP_ALREADY_EXISTS'\n | 'SWAP_ALREADY_COMPLETED'\n | 'SWAP_ALREADY_CANCELLED'\n | 'SWAP_TIMEOUT'\n | 'SWAP_LIMIT_EXCEEDED'\n | 'SWAP_ALREADY_INITIALIZED'\n | 'SWAP_MODULE_DESTROYED'\n | 'SWAP_NOT_INITIALIZED';\n\nexport class SphereError extends Error {\n readonly code: SphereErrorCode;\n readonly cause?: unknown;\n\n constructor(message: string, code: SphereErrorCode, cause?: unknown) {\n super(message);\n this.name = 'SphereError';\n this.code = code;\n this.cause = cause;\n }\n}\n\n/**\n * Type guard to check if an error is a SphereError\n */\nexport function isSphereError(err: unknown): err is SphereError {\n return err instanceof SphereError;\n}\n","/**\n * Centralized SDK Logger\n *\n * A lightweight singleton logger that works across all tsup bundles\n * by storing state on globalThis. Supports three log levels:\n * - debug: detailed messages (only shown when debug=true)\n * - warn: important warnings (ALWAYS shown regardless of debug flag)\n * - error: critical errors (ALWAYS shown regardless of debug flag)\n *\n * Global debug flag enables all logging. Per-tag overrides allow\n * granular control (e.g., only transport debug).\n *\n * @example\n * ```ts\n * import { logger } from '@unicitylabs/sphere-sdk';\n *\n * // Enable all debug logging\n * logger.configure({ debug: true });\n *\n * // Enable only specific tags\n * logger.setTagDebug('Nostr', true);\n *\n * // Usage in SDK classes\n * logger.debug('Payments', 'Transfer started', { amount, recipient });\n * logger.warn('Nostr', 'queryEvents timed out after 5s');\n * logger.error('Sphere', 'Critical failure', error);\n * ```\n */\n\nexport type LogLevel = 'debug' | 'warn' | 'error';\n\nexport type LogHandler = (level: LogLevel, tag: string, message: string, ...args: unknown[]) => void;\n\nexport interface LoggerConfig {\n /** Enable debug logging globally (default: false). When false, only warn and error messages are shown. */\n debug?: boolean;\n /** Custom log handler. If provided, replaces console output. Useful for tests or custom log sinks. */\n handler?: LogHandler | null;\n}\n\n// Use a unique symbol-like key on globalThis to share logger state across tsup bundles\nconst LOGGER_KEY = '__sphere_sdk_logger__';\n\ninterface LoggerState {\n debug: boolean;\n tags: Record<string, boolean>;\n handler: LogHandler | null;\n}\n\nfunction getState(): LoggerState {\n const g = globalThis as unknown as Record<string, unknown>;\n if (!g[LOGGER_KEY]) {\n g[LOGGER_KEY] = { debug: false, tags: {}, handler: null } satisfies LoggerState;\n }\n return g[LOGGER_KEY] as LoggerState;\n}\n\nfunction isEnabled(tag: string): boolean {\n const state = getState();\n // Per-tag override takes priority\n if (tag in state.tags) return state.tags[tag];\n // Fall back to global flag\n return state.debug;\n}\n\nexport const logger = {\n /**\n * Configure the logger. Can be called multiple times (last write wins).\n * Typically called by createBrowserProviders(), createNodeProviders(), or Sphere.init().\n */\n configure(config: LoggerConfig): void {\n const state = getState();\n if (config.debug !== undefined) state.debug = config.debug;\n if (config.handler !== undefined) state.handler = config.handler;\n },\n\n /**\n * Enable/disable debug logging for a specific tag.\n * Per-tag setting overrides the global debug flag.\n *\n * @example\n * ```ts\n * logger.setTagDebug('Nostr', true); // enable only Nostr logs\n * logger.setTagDebug('Nostr', false); // disable Nostr logs even if global debug=true\n * ```\n */\n setTagDebug(tag: string, enabled: boolean): void {\n getState().tags[tag] = enabled;\n },\n\n /**\n * Clear per-tag override, falling back to global debug flag.\n */\n clearTagDebug(tag: string): void {\n delete getState().tags[tag];\n },\n\n /** Returns true if debug mode is enabled for the given tag (or globally). */\n isDebugEnabled(tag?: string): boolean {\n if (tag) return isEnabled(tag);\n return getState().debug;\n },\n\n /**\n * Debug-level log. Only shown when debug is enabled (globally or for this tag).\n * Use for detailed operational information.\n */\n debug(tag: string, message: string, ...args: unknown[]): void {\n if (!isEnabled(tag)) return;\n const state = getState();\n if (state.handler) {\n state.handler('debug', tag, message, ...args);\n } else {\n console.log(`[${tag}]`, message, ...args);\n }\n },\n\n /**\n * Warning-level log. ALWAYS shown regardless of debug flag.\n * Use for important but non-critical issues (timeouts, retries, degraded state).\n */\n warn(tag: string, message: string, ...args: unknown[]): void {\n const state = getState();\n if (state.handler) {\n state.handler('warn', tag, message, ...args);\n } else {\n console.warn(`[${tag}]`, message, ...args);\n }\n },\n\n /**\n * Error-level log. ALWAYS shown regardless of debug flag.\n * Use for critical failures that should never be silenced.\n */\n error(tag: string, message: string, ...args: unknown[]): void {\n const state = getState();\n if (state.handler) {\n state.handler('error', tag, message, ...args);\n } else {\n console.error(`[${tag}]`, message, ...args);\n }\n },\n\n /** Reset all logger state (debug flag, tags, handler). Primarily for tests. */\n reset(): void {\n const g = globalThis as unknown as Record<string, unknown>;\n delete g[LOGGER_KEY];\n },\n};\n","/**\n * token-engine/SpherePaymentData.ts — the sphere value model.\n *\n * v2 `Token` carries no coins; value is app-defined and stored in\n * `MintTransaction.data`. `SpherePaymentData` is that payload: it implements the\n * SDK's `IPaymentData` (so `TokenSplit` can read it for value conservation) and\n * encodes a `PaymentAssetCollection` inside a versioned, tagged CBOR envelope.\n *\n * The SDK never inspects our raw bytes — it only calls `decodePaymentData(data)`\n * and reads `.assets` — so the envelope (tag + version) is ours, chosen for\n * forward-compatible storage. `fromValue`/`toValue` bridge sphere-domain values\n * (hex coin id + bigint amount) to/from the SDK asset collection.\n */\n\nimport {\n Asset,\n AssetId,\n CborDeserializer,\n CborError,\n CborSerializer,\n HexConverter,\n type IPaymentData,\n PaymentAssetCollection,\n} from './sdk';\nimport type { CoinId, SphereValue } from './types';\nimport { SphereError } from '../core/errors';\n\n/** Canonical coin id: non-empty, even-length lowercase hex (the form `toValue` emits). */\nconst COIN_ID_PATTERN = /^([0-9a-f]{2})+$/;\n\n/** Guard a sphere-domain asset before it crosses into the SDK value model. */\nfunction assertAsset(coinId: CoinId, amount: bigint): void {\n if (!COIN_ID_PATTERN.test(coinId)) {\n throw new SphereError(`Invalid coin id (expected even-length lowercase hex): \"${coinId}\"`, 'VALIDATION_ERROR');\n }\n if (amount < 0n) {\n // Negative bigints silently encode to an empty byte string (decoding back to 0n)\n // in the SDK's BigintConverter — reject loudly to avoid silent value loss.\n throw new SphereError(`Asset amount must be non-negative: ${amount.toString()}`, 'VALIDATION_ERROR');\n }\n}\n\n/** Validate a sphere-domain asset and build the SDK Asset — the single validation point. */\nexport function sphereAssetToSdk(coinId: CoinId, amount: bigint): Asset {\n assertAsset(coinId, amount);\n return new Asset(new AssetId(HexConverter.decode(coinId)), amount);\n}\n\nexport class SpherePaymentData implements IPaymentData {\n /** Sphere-private CBOR tag (verified free in the v2 SDK tag space). */\n public static readonly CBOR_TAG = 39050n;\n /** Envelope version; bump when the structure changes. */\n public static readonly VERSION = 1n;\n\n private constructor(\n public readonly assets: PaymentAssetCollection,\n private readonly _memo: Uint8Array | null = null,\n ) {}\n\n /** Opaque, app-defined memo carried alongside the value (e.g. invoice attribution). */\n public get memo(): Uint8Array | null {\n return this._memo ? new Uint8Array(this._memo) : null;\n }\n\n /** Wrap an existing SDK asset collection (+ optional opaque memo). */\n public static create(assets: PaymentAssetCollection, memo: Uint8Array | null = null): SpherePaymentData {\n return new SpherePaymentData(assets, memo);\n }\n\n /** Build from a sphere-domain value (hex coin id → bigint amount) + optional opaque memo. */\n public static fromValue(value: SphereValue, memo: Uint8Array | null = null): SpherePaymentData {\n const assets = value.assets.map((a) => sphereAssetToSdk(a.coinId, a.amount));\n return new SpherePaymentData(PaymentAssetCollection.create(...assets), memo);\n }\n\n /** Decode from the CBOR envelope produced by {@link encode}. */\n public static fromCBOR(bytes: Uint8Array): SpherePaymentData {\n const tag = CborDeserializer.decodeTag(bytes);\n if (tag.tag !== SpherePaymentData.CBOR_TAG) {\n throw new CborError(`Invalid SpherePaymentData tag: ${tag.tag}`);\n }\n // Strict structure: exactly [version, assets, memo] (matches encode + the SDK's\n // fixed-shape decoders). Extra/missing fields are corruption, not tolerated.\n const fields = CborDeserializer.decodeArray(tag.data, 3);\n const version = CborDeserializer.decodeUnsignedInteger(fields[0]);\n if (version !== SpherePaymentData.VERSION) {\n throw new CborError(`Unsupported SpherePaymentData version: ${version}`);\n }\n const memo = CborDeserializer.decodeNullable(fields[2], CborDeserializer.decodeByteString);\n return new SpherePaymentData(PaymentAssetCollection.fromCBOR(fields[1]), memo);\n }\n\n /** Deterministic, versioned, tagged CBOR: `tag(39050)[ version, assets, memo? ]`. */\n public encode(): Promise<Uint8Array> {\n return Promise.resolve(\n CborSerializer.encodeTag(\n SpherePaymentData.CBOR_TAG,\n CborSerializer.encodeArray(\n CborSerializer.encodeUnsignedInteger(SpherePaymentData.VERSION),\n this.assets.toCBOR(),\n CborSerializer.encodeNullable(this._memo, CborSerializer.encodeByteString),\n ),\n ),\n );\n }\n\n /** Project to a sphere-domain value (hex coin id + bigint amount), preserving order. */\n public toValue(): SphereValue {\n return {\n assets: this.assets.toArray().map((a) => ({\n coinId: HexConverter.encode(a.id.bytes) as CoinId,\n amount: a.value,\n })),\n };\n }\n\n /** Balance of a single coin within this payload (0n when absent). */\n public balanceOf(coinId: CoinId): bigint {\n if (!COIN_ID_PATTERN.test(coinId)) {\n throw new SphereError(`Invalid coin id (expected even-length lowercase hex): \"${coinId}\"`, 'VALIDATION_ERROR');\n }\n const asset = this.assets.get(new AssetId(HexConverter.decode(coinId)));\n return asset ? asset.value : 0n;\n }\n}\n\n/**\n * Async payment-data decoder matching the SDK's `decodePaymentData` signature.\n * Used by `TokenSplit.split` (value conservation) and `SplitMintJustificationVerifier`.\n */\nexport function decodeSpherePaymentData(bytes: Uint8Array): Promise<IPaymentData> {\n return Promise.resolve(SpherePaymentData.fromCBOR(bytes));\n}\n","/**\n * token-engine/token-blob.ts — storage/transport codec for a wallet token.\n *\n * A {@link TokenBlob} is `{ v, network, tokenId, token }` where `token` is the v2\n * `Token.toCBOR()` bytes and `tokenId` is the genesis-stable id (stored so dedup /\n * listing / tombstone keys need no engine call). This codec wraps it in a\n * sphere-private CBOR envelope so the wallet's own storage format can version\n * independently of the SDK's token CBOR. The decoded value is re-derivable from\n * `token`, so it is NOT stored here.\n */\n\nimport { CborDeserializer, CborError, CborSerializer } from './sdk';\nimport type { TokenBlob } from './types';\n\n/** Sphere-private CBOR tag (distinct from SpherePaymentData's 39050). */\nconst TOKEN_BLOB_TAG = 39051n;\n/** Current blob envelope version. */\nexport const TOKEN_BLOB_VERSION = 1;\n\n/** Encode a blob as `tag(39051)[ v, network, tokenId, token ]`. */\nexport function encodeTokenBlob(blob: TokenBlob): Uint8Array {\n return CborSerializer.encodeTag(\n TOKEN_BLOB_TAG,\n CborSerializer.encodeArray(\n CborSerializer.encodeUnsignedInteger(BigInt(blob.v)),\n CborSerializer.encodeUnsignedInteger(BigInt(blob.network)),\n CborSerializer.encodeTextString(blob.tokenId),\n CborSerializer.encodeByteString(blob.token),\n ),\n );\n}\n\n/** Decode a blob produced by {@link encodeTokenBlob}. */\nexport function decodeTokenBlob(bytes: Uint8Array): TokenBlob {\n const tag = CborDeserializer.decodeTag(bytes);\n if (tag.tag !== TOKEN_BLOB_TAG) {\n throw new CborError(`Invalid TokenBlob tag: ${tag.tag}`);\n }\n const fields = CborDeserializer.decodeArray(tag.data, 4);\n const v = Number(CborDeserializer.decodeUnsignedInteger(fields[0]));\n if (v !== TOKEN_BLOB_VERSION) {\n throw new CborError(`Unsupported TokenBlob version: ${v}`);\n }\n return {\n v,\n network: Number(CborDeserializer.decodeUnsignedInteger(fields[1])),\n tokenId: CborDeserializer.decodeTextString(fields[2]),\n token: CborDeserializer.decodeByteString(fields[3]),\n };\n}\n","/**\n * token-engine/SphereTokenEngine.ts — the real ITokenEngine adapter (Track A).\n *\n * The full sender-driven engine over the v2 SDK: identity, value reads,\n * serialization, verification, mint, transfer, split and spent-status. All\n * crypto/value logic is the SDK's; this class orchestrates build → submit →\n * wait-proof → certify → realize, and maps SDK errors/states to the\n * sphere-domain ITokenEngine port.\n *\n * SDK objects are injected via `EngineDeps` (built by the factory in A4, or by\n * test wiring around TestAggregatorClient), keeping the engine logic independent\n * of how the aggregator/trust base are constructed.\n */\n\nimport { SphereError } from '../core/errors';\nimport { deriveDirectAddress } from './identity';\nimport {\n CborDeserializer,\n CertificationData,\n CertificationStatus,\n EncodedPredicate,\n HexConverter,\n type MintJustificationVerifierService,\n MintTransaction,\n type NetworkId,\n PaymentAssetCollection,\n type PredicateVerifierService,\n type RootTrustBase,\n SignaturePredicate,\n SignaturePredicateUnlockScript,\n type SigningService,\n SplitMintJustification,\n SplitTokenRequest,\n StateId,\n type StateTransitionClient,\n Token,\n TokenSalt,\n TokenSplit,\n TokenType,\n TransferTransaction,\n VerificationStatus,\n waitInclusionProof,\n} from './sdk';\nimport { decodeSpherePaymentData, SpherePaymentData, sphereAssetToSdk } from './SpherePaymentData';\nimport { TOKEN_BLOB_VERSION } from './token-blob';\nimport type { EngineOpOptions, ITokenEngine } from './engine';\nimport type {\n CoinId,\n EngineIdentity,\n EngineVerifyResult,\n MintDataTokenParams,\n MintParams,\n SphereToken,\n SphereValue,\n SplitParams,\n SplitResult,\n TokenBlob,\n TransferParams,\n} from './types';\n\n/** SDK objects the engine operates with; assembled by the factory (A4) or test wiring. */\nexport interface EngineDeps {\n readonly client: StateTransitionClient;\n readonly trustBase: RootTrustBase;\n readonly predicateVerifier: PredicateVerifierService;\n readonly mintJustificationVerifier: MintJustificationVerifierService;\n /** The wallet's signing key (its identity + the spender for transfers it owns). */\n readonly signingService: SigningService;\n readonly networkId: NetworkId;\n}\n\nexport class SphereTokenEngine implements ITokenEngine {\n public constructor(private readonly deps: EngineDeps) {}\n\n // ── identity ────────────────────────────────────────────────────────────────\n\n public getIdentity(): EngineIdentity {\n return { chainPubkey: new Uint8Array(this.deps.signingService.publicKey) };\n }\n\n /** Legacy DIRECT:// address (Path A). Async: the derivation hashes via the SDK. */\n public deriveIdentityAddress(pubkey?: Uint8Array): Promise<string> {\n return deriveDirectAddress(pubkey ?? this.deps.signingService.publicKey);\n }\n\n // ── value (read) ─────────────────────────────────────────────────────────────\n\n public readValue(token: SphereToken): SphereValue | null {\n return token.value;\n }\n\n public balanceOf(token: SphereToken, coinId: CoinId): bigint {\n let sum = 0n;\n for (const asset of token.value?.assets ?? []) {\n if (asset.coinId === coinId) sum += asset.amount;\n }\n return sum;\n }\n\n public tokenId(token: SphereToken): string {\n return token.blob.tokenId;\n }\n\n public readMemo(token: SphereToken): Uint8Array | null {\n const sdkToken = token.sdkToken;\n // A transferred token delivers its memo on the latest transfer.\n if (sdkToken.transactions.length > 0) {\n return sdkToken.latestTransaction.data;\n }\n // A minted output (e.g. a split output) carries the memo in its value envelope.\n const data = sdkToken.genesis.data;\n if (data && this.isSpherePaymentData(data)) {\n return SpherePaymentData.fromCBOR(data).memo;\n }\n return null;\n }\n\n public readTokenData(token: SphereToken): Uint8Array | null {\n const data = token.sdkToken.genesis.data;\n return data ? new Uint8Array(data) : null;\n }\n\n // ── lifecycle ────────────────────────────────────────────────────────────────\n\n public async mint(params: MintParams, options?: EngineOpOptions): Promise<SphereToken> {\n const recipient = SignaturePredicate.create(params.recipientPubkey);\n const data = params.value ? await SpherePaymentData.fromValue(params.value).encode() : null;\n\n const mintTx = await MintTransaction.create(this.deps.networkId, recipient, data);\n const certificationData = await CertificationData.fromMintTransaction(mintTx);\n\n const response = await this.deps.client.submitCertificationRequest(certificationData);\n if (response.status !== CertificationStatus.SUCCESS) {\n throw new SphereError(`Mint certification failed: ${response.status}`, 'AGGREGATOR_ERROR');\n }\n\n const proof = await waitInclusionProof(\n this.deps.client,\n this.deps.trustBase,\n this.deps.predicateVerifier,\n mintTx,\n options?.signal,\n );\n const certified = await mintTx.toCertifiedTransaction(this.deps.trustBase, this.deps.predicateVerifier, proof);\n const token = await Token.mint(\n this.deps.trustBase,\n this.deps.predicateVerifier,\n this.deps.mintJustificationVerifier,\n certified,\n );\n return this.wrapToken(token);\n }\n\n public async mintDataToken(params: MintDataTokenParams, options?: EngineOpOptions): Promise<SphereToken> {\n const recipient = SignaturePredicate.create(params.recipientPubkey);\n const tokenType = params.tokenType ? new TokenType(params.tokenType) : TokenType.generate();\n // A deterministic salt yields a stable, terms-derived tokenId (TokenId.fromSalt).\n const salt = params.salt ? TokenSalt.fromBytes(params.salt) : TokenSalt.generate();\n\n const mintTx = await MintTransaction.create(this.deps.networkId, recipient, params.data, tokenType, salt);\n const certificationData = await CertificationData.fromMintTransaction(mintTx);\n\n const response = await this.deps.client.submitCertificationRequest(certificationData);\n if (response.status !== CertificationStatus.SUCCESS) {\n throw new SphereError(`Data-token mint failed: ${response.status}`, 'AGGREGATOR_ERROR');\n }\n\n const proof = await waitInclusionProof(\n this.deps.client,\n this.deps.trustBase,\n this.deps.predicateVerifier,\n mintTx,\n options?.signal,\n );\n const certified = await mintTx.toCertifiedTransaction(this.deps.trustBase, this.deps.predicateVerifier, proof);\n const token = await Token.mint(\n this.deps.trustBase,\n this.deps.predicateVerifier,\n this.deps.mintJustificationVerifier,\n certified,\n );\n return this.wrapToken(token);\n }\n\n public async transfer(params: TransferParams, options?: EngineOpOptions): Promise<SphereToken> {\n this.assertOwned(params.token);\n const recipient = SignaturePredicate.create(params.recipientPubkey);\n const stateMask = crypto.getRandomValues(new Uint8Array(32));\n\n const transferTx = await TransferTransaction.create(params.token.sdkToken, recipient, stateMask, params.data ?? null);\n const unlockScript = await SignaturePredicateUnlockScript.create(transferTx, this.deps.signingService);\n const certificationData = await CertificationData.fromTransaction(transferTx, unlockScript);\n\n const response = await this.deps.client.submitCertificationRequest(certificationData);\n if (response.status !== CertificationStatus.SUCCESS) {\n throw new SphereError(`Transfer certification failed: ${response.status}`, 'TRANSFER_FAILED');\n }\n\n const proof = await waitInclusionProof(\n this.deps.client,\n this.deps.trustBase,\n this.deps.predicateVerifier,\n transferTx,\n options?.signal,\n );\n const certified = await transferTx.toCertifiedTransaction(this.deps.trustBase, this.deps.predicateVerifier, proof);\n const transferred = await params.token.sdkToken.transfer(this.deps.trustBase, this.deps.predicateVerifier, certified);\n return this.wrapToken(transferred);\n }\n\n public async split(params: SplitParams, options?: EngineOpOptions): Promise<SplitResult> {\n this.assertOwned(params.token);\n if (params.outputs.length === 0) {\n throw new SphereError('Split requires at least one output', 'VALIDATION_ERROR');\n }\n\n const requests = params.outputs.map((o) =>\n SplitTokenRequest.create(\n SignaturePredicate.create(o.recipientPubkey),\n PaymentAssetCollection.create(sphereAssetToSdk(o.coinId, o.amount)),\n ),\n );\n\n // Value conservation is enforced inside the SDK split (root.value === source value).\n const split = await TokenSplit.split(params.token.sdkToken, decodeSpherePaymentData, requests);\n\n // 1. Burn the source: certify the burn transfer and append it -> burntToken.\n const burnUnlock = await SignaturePredicateUnlockScript.create(split.burn.transaction, this.deps.signingService);\n const burnCert = await CertificationData.fromTransaction(split.burn.transaction, burnUnlock);\n const burnResponse = await this.deps.client.submitCertificationRequest(burnCert);\n if (burnResponse.status !== CertificationStatus.SUCCESS) {\n throw new SphereError(`Split burn failed: ${burnResponse.status}`, 'TRANSFER_FAILED');\n }\n const burnProof = await waitInclusionProof(\n this.deps.client,\n this.deps.trustBase,\n this.deps.predicateVerifier,\n split.burn.transaction,\n options?.signal,\n );\n const burnCertified = await split.burn.transaction.toCertifiedTransaction(\n this.deps.trustBase,\n this.deps.predicateVerifier,\n burnProof,\n );\n const burntToken = await params.token.sdkToken.transfer(\n this.deps.trustBase,\n this.deps.predicateVerifier,\n burnCertified,\n );\n\n // 2. Mint each output, justified by the burnt token + its split proofs.\n const outputs: SphereToken[] = [];\n for (let i = 0; i < split.tokens.length; i++) {\n const splitToken = split.tokens[i];\n // split.tokens preserves requests order, so the per-output memo maps by index.\n const data = await SpherePaymentData.create(splitToken.assets, params.outputs[i].data ?? null).encode();\n const justification = SplitMintJustification.create(burntToken, splitToken.proofs).toCBOR();\n const mintTx = await MintTransaction.create(\n splitToken.networkId,\n splitToken.recipient,\n data,\n splitToken.tokenType,\n splitToken.salt,\n justification,\n );\n const certData = await CertificationData.fromMintTransaction(mintTx);\n const response = await this.deps.client.submitCertificationRequest(certData);\n if (response.status !== CertificationStatus.SUCCESS) {\n throw new SphereError(`Split mint failed: ${response.status}`, 'AGGREGATOR_ERROR');\n }\n const proof = await waitInclusionProof(\n this.deps.client,\n this.deps.trustBase,\n this.deps.predicateVerifier,\n mintTx,\n options?.signal,\n );\n const certified = await mintTx.toCertifiedTransaction(this.deps.trustBase, this.deps.predicateVerifier, proof);\n const token = await Token.mint(\n this.deps.trustBase,\n this.deps.predicateVerifier,\n this.deps.mintJustificationVerifier,\n certified,\n );\n outputs.push(this.wrapToken(token));\n }\n\n return { outputs };\n }\n\n // ── verification ─────────────────────────────────────────────────────────────\n\n public async verify(token: SphereToken, _options?: EngineOpOptions): Promise<EngineVerifyResult> {\n const result = await token.sdkToken.verify(\n this.deps.trustBase,\n this.deps.predicateVerifier,\n this.deps.mintJustificationVerifier,\n );\n return result.status === VerificationStatus.OK ? { ok: true } : { ok: false, reason: String(result.status) };\n }\n\n public isOwnedBy(token: SphereToken, pubkey: Uint8Array): boolean {\n const owner = token.sdkToken.latestTransaction.recipient;\n const claimed = EncodedPredicate.fromPredicate(SignaturePredicate.create(pubkey));\n return EncodedPredicate.equals(owner, claimed);\n }\n\n public async isSpent(token: SphereToken, _options?: EngineOpOptions): Promise<boolean> {\n // The token's current state id = what a future transfer would spend. Derive it via a\n // probe transfer (never submitted) — StateId depends only on the source's lock script\n // and state hash, not on the recipient or state mask.\n const probe = await TransferTransaction.create(\n token.sdkToken,\n SignaturePredicate.create(this.deps.signingService.publicKey),\n new Uint8Array(32),\n );\n const stateId = await StateId.fromTransaction(probe);\n const response = await this.deps.client.getInclusionProof(stateId);\n // A present inclusion certificate means the state has already been consumed on-chain.\n return response.inclusionProof.inclusionCertificate !== null;\n }\n\n // ── serialization ────────────────────────────────────────────────────────────\n\n public encodeToken(token: SphereToken): TokenBlob {\n return token.blob;\n }\n\n public async decodeToken(blob: TokenBlob): Promise<SphereToken> {\n const sdkToken = await Token.fromCBOR(blob.token);\n if (sdkToken.genesis.networkId.id !== this.deps.networkId.id) {\n throw new SphereError(\n `Token network mismatch: token is on network ${sdkToken.genesis.networkId.id}, ` +\n `engine on ${this.deps.networkId.id}`,\n 'VALIDATION_ERROR',\n );\n }\n return this.wrapToken(sdkToken);\n }\n\n // ── internals ────────────────────────────────────────────────────────────────\n\n /** Fail fast if this engine's key does not own the token's current state. */\n private assertOwned(token: SphereToken): void {\n if (!this.isOwnedBy(token, this.deps.signingService.publicKey)) {\n throw new SphereError('Cannot transfer a token not owned by this engine identity', 'VALIDATION_ERROR');\n }\n }\n\n /** Wrap an SDK token into a SphereToken: cache its blob (incl. stable tokenId) + decoded value. */\n private wrapToken(sdkToken: Token): SphereToken {\n const data = sdkToken.genesis.data;\n let value: SphereValue | null = null;\n // Only value tokens carry a SpherePaymentData envelope; data tokens (e.g. invoices)\n // leave value === null. A corrupt value envelope still errors loudly.\n if (data && this.isSpherePaymentData(data)) {\n try {\n value = SpherePaymentData.fromCBOR(data).toValue();\n } catch (err) {\n throw new SphereError(\n `Failed to decode token payment data: ${err instanceof Error ? err.message : String(err)}`,\n 'VALIDATION_ERROR',\n );\n }\n }\n const blob: TokenBlob = {\n v: TOKEN_BLOB_VERSION,\n network: sdkToken.genesis.networkId.id,\n tokenId: HexConverter.encode(sdkToken.id.bytes),\n token: sdkToken.toCBOR(),\n };\n return { sdkToken, blob, value };\n }\n\n /** True if the bytes are a SpherePaymentData envelope (value token) vs a raw data token. */\n private isSpherePaymentData(data: Uint8Array): boolean {\n try {\n return CborDeserializer.decodeTag(data).tag === SpherePaymentData.CBOR_TAG;\n } catch {\n return false;\n }\n }\n}\n","/**\n * token-engine/factory.ts — the real engine constructor (A4).\n *\n * `createSphereTokenEngine` is the public way to obtain an ITokenEngine. It maps\n * the sphere-domain EngineConfig to the SDK objects the engine needs: the\n * aggregator client (from `aggregatorUrl`), the trust base (parsed from\n * `trustBaseJson`), the wallet signing key (from `privateKey`), the network id,\n * and a mint-justification verifier with the split verifier registered (so\n * split-output tokens verify).\n *\n * Loading the trust base per environment (browser fetch / node file) stays with\n * the caller (impl/<env>/oracle, reusing the existing trust-base loaders); it\n * passes the parsed JSON in via `trustBaseJson`, keeping this factory env-agnostic.\n */\n\nimport { SphereError } from '../core/errors';\nimport { logger } from '../core/logger';\nimport {\n AggregatorClient,\n MintJustificationVerifierService,\n PredicateVerifierService,\n RootTrustBase,\n SigningService,\n SplitMintJustificationVerifier,\n StateTransitionClient,\n} from './sdk';\nimport { decodeSpherePaymentData } from './SpherePaymentData';\nimport { type EngineDeps, SphereTokenEngine } from './SphereTokenEngine';\nimport type { EngineConfig, ITokenEngine } from './engine';\n\nexport async function createSphereTokenEngine(config: EngineConfig): Promise<ITokenEngine> {\n if (config.trustBaseJson == null) {\n throw new SphereError('Engine config requires a trust base (trustBaseJson)', 'INVALID_CONFIG');\n }\n\n if (!config.apiKey) {\n logger.warn(\n 'TokenEngine',\n 'No aggregator apiKey — pass config.oracle.apiKey (testnet2 value in .env.example; mainnet from a secret env var). Gateway requests will be unauthenticated.',\n );\n }\n\n const trustBase = RootTrustBase.fromJSON(config.trustBaseJson);\n const predicateVerifier = PredicateVerifierService.create();\n const mintJustificationVerifier = new MintJustificationVerifierService();\n mintJustificationVerifier.register(\n new SplitMintJustificationVerifier(trustBase, predicateVerifier, decodeSpherePaymentData),\n );\n\n const deps: EngineDeps = {\n client: new StateTransitionClient(new AggregatorClient(config.aggregatorUrl, config.apiKey ?? null)),\n trustBase,\n predicateVerifier,\n mintJustificationVerifier,\n signingService: new SigningService(config.privateKey),\n // The trust base is the single source of truth for the network id (it carries\n // NetworkId.fromId, so any id works — e.g. testnet2 = 4 — with no enum entry).\n networkId: trustBase.networkId,\n };\n\n return new SphereTokenEngine(deps);\n}\n","/**\n * token-engine/unicity-id.ts — self-issued v2 UnicityIdToken mint (the v2 analog\n * of the v1 nametag-token mint).\n *\n * User decision 2026-06-10: the on-chain Unicity ID claim is minted AND STORED\n * again at nametag registration (it was retired with v1 in Track B / D5), but it\n * is NOT used at runtime — name resolution stays Nostr-binding-only, receive\n * stays SignaturePredicate(chainPubkey), and no PROXY semantics return. The\n * token is kept for the future (e.g. an issuer/verification model).\n *\n * Trust model: SELF-ISSUED. The wallet's own key is the issuer lock script, the\n * recipient AND the target predicate (the v2 local-mint path — the issuer pin is\n * only meaningful when verifying third-party tokens). Because the issuer lock\n * script is part of the StateId, on-chain uniqueness is per-issuer only; GLOBAL\n * name uniqueness remains the Nostr first-seen-wins binding's job (unchanged).\n *\n * Determinism / idempotency: tokenId = SHA256(CBOR[\"NAMETAG_\", null, name]),\n * tokenType is pinned (UNICITY_TOKEN_TYPE_HEX), and all predicates derive from\n * the wallet key — the whole mint transaction is reproducible byte-for-byte, so\n * a re-mint (e.g. after the token was lost from local storage) re-certifies the\n * same state and yields the identical token (the v1 REQUEST_ID_EXISTS recovery\n * analog).\n */\n\nimport { SphereError } from '../core/errors';\nimport { logger } from '../core/logger';\nimport {\n AggregatorClient,\n CertificationData,\n CertificationStatus,\n HexConverter,\n PredicateVerifierService,\n RootTrustBase,\n SignaturePredicate,\n SignaturePredicateUnlockScript,\n SigningService,\n StateTransitionClient,\n TokenType,\n UnicityId,\n UnicityIdMintTransaction,\n UnicityIdToken,\n waitInclusionProof,\n} from './sdk';\nimport { UNICITY_TOKEN_TYPE_HEX } from './identity';\nimport type { EngineConfig, EngineOpOptions } from './engine';\n\nexport interface UnicityIdMintResult {\n /** UnicityIdToken CBOR, hex-encoded — the storable form (UnicityIdToken.fromCBOR round-trips it). */\n readonly tokenCborHex: string;\n /** 64-char hex token id, derived from the name (stable across re-mints). */\n readonly tokenId: string;\n}\n\n/** Self-issued Unicity ID (nametag) token minter. */\nexport interface IUnicityIdMinter {\n /**\n * Mint (or idempotently re-certify) the UnicityIdToken for `name`,\n * self-issued by this wallet's key. Network-bound: submits the certification\n * request and waits for the inclusion proof.\n */\n mintUnicityIdToken(name: string, options?: EngineOpOptions): Promise<UnicityIdMintResult>;\n}\n\nclass SelfIssuedUnicityIdMinter implements IUnicityIdMinter {\n public constructor(\n private readonly client: StateTransitionClient,\n private readonly trustBase: RootTrustBase,\n private readonly predicateVerifier: PredicateVerifierService,\n private readonly signingService: SigningService,\n ) {}\n\n public async mintUnicityIdToken(name: string, options?: EngineOpOptions): Promise<UnicityIdMintResult> {\n const unicityId = new UnicityId(name);\n const self = SignaturePredicate.fromSigningService(this.signingService);\n\n // Deterministic per (name, wallet key): pinned token type, self predicates.\n const mintTx = await UnicityIdMintTransaction.create(\n self, // issuer lock script (self-issued)\n self, // recipient — locks the minted token state to this wallet\n unicityId,\n new TokenType(HexConverter.decode(UNICITY_TOKEN_TYPE_HEX)),\n self, // target predicate the unicity id resolves to\n );\n\n const certificationData = await CertificationData.fromTransaction(\n mintTx,\n await SignaturePredicateUnlockScript.create(mintTx, this.signingService),\n );\n\n const response = await this.client.submitCertificationRequest(certificationData);\n if (response.status !== CertificationStatus.SUCCESS) {\n // The transaction is deterministic: when this wallet minted the name\n // before, its certification is already on-chain and the proof below\n // still verifies (idempotent re-mint). Any genuine failure surfaces as\n // a proof-wait timeout/verification error instead.\n logger.warn(\n 'UnicityIdMinter',\n `Certification request returned ${response.status} for \"@${name}\" — attempting proof recovery (idempotent re-mint).`,\n );\n }\n\n try {\n const proof = await waitInclusionProof(\n this.client,\n this.trustBase,\n this.predicateVerifier,\n mintTx,\n options?.signal,\n );\n const certified = await mintTx.toCertifiedTransaction(this.trustBase, this.predicateVerifier, proof);\n const token = await UnicityIdToken.mint(this.trustBase, this.predicateVerifier, certified);\n return {\n tokenCborHex: HexConverter.encode(token.toCBOR()),\n tokenId: HexConverter.encode(token.id.bytes),\n };\n } catch (err) {\n const detail = err instanceof Error ? err.message : String(err);\n throw new SphereError(\n `Unicity ID mint failed for \"@${name}\": ${detail}` +\n (response.status !== CertificationStatus.SUCCESS ? ` (certification status: ${response.status})` : ''),\n 'AGGREGATOR_ERROR',\n );\n }\n }\n}\n\n/** SDK objects the minter operates with (test seam; mirrors EngineDeps). */\nexport interface UnicityIdMinterDeps {\n readonly client: StateTransitionClient;\n readonly trustBase: RootTrustBase;\n readonly predicateVerifier: PredicateVerifierService;\n readonly signingService: SigningService;\n}\n\n/** Build the minter from pre-constructed SDK objects (tests / shared wiring). */\nexport function createUnicityIdMinterFromDeps(deps: UnicityIdMinterDeps): IUnicityIdMinter {\n return new SelfIssuedUnicityIdMinter(deps.client, deps.trustBase, deps.predicateVerifier, deps.signingService);\n}\n\n/**\n * Build the self-issued Unicity ID minter from the same config the token engine\n * uses (trust base JSON + gateway URL + API key + wallet key).\n */\nexport function createUnicityIdMinter(config: EngineConfig): IUnicityIdMinter {\n if (config.trustBaseJson == null) {\n throw new SphereError('Unicity ID minter requires a trust base (trustBaseJson)', 'INVALID_CONFIG');\n }\n const trustBase = RootTrustBase.fromJSON(config.trustBaseJson);\n return new SelfIssuedUnicityIdMinter(\n new StateTransitionClient(new AggregatorClient(config.aggregatorUrl, config.apiKey ?? null)),\n trustBase,\n PredicateVerifierService.create(),\n new SigningService(config.privateKey),\n );\n}\n"],"mappings":";AAaA,SAAS,6BAA6B;AACtC,SAAS,wBAAwB;AAEjC,SAAS,iBAAiB;AAC1B,SAAS,yBAAyB;AAClC,SAAS,uBAAuB,2BAA2B;AAC3D,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAC/B,SAAS,8BAA8B;AACvC,SAAS,qBAAqB;AAC9B,SAAS,0BAA0B;AAGnC,SAAS,aAAa;AACtB,SAAS,uBAAuB;AAChC,SAAS,2BAA2B;AACpC,SAAS,gCAAgC;AACzC,SAAS,oCAAoC;AAC7C,SAAS,eAAe;AACxB,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAE1B,SAAS,wCAAwC;AAKjD,SAAS,wBAAwB;AACjC,SAAS,0BAA0B;AACnC,SAAS,sCAAsC;AAC/C,SAAS,qBAAqB;AAC9B,SAAS,gCAAgC;AAGzC,SAAS,sBAAsB;AAC/B,SAAS,iBAAiB;AAC1B,SAAS,0BAA0B;AACnC,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,yBAAyB;AAGlC,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC,SAAS,iBAAiB;AAI1B,SAAS,aAAa;AACtB,SAAS,eAAe;AACxB,SAAS,8BAA8B;AACvC,SAAS,kBA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dk",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1-dev.0",
|
|
4
4
|
"description": "Modular TypeScript SDK for Unicity wallet operations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -45,6 +45,16 @@
|
|
|
45
45
|
"default": "./dist/core/index.cjs"
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
|
+
"./token-engine": {
|
|
49
|
+
"import": {
|
|
50
|
+
"types": "./dist/token-engine/index.d.ts",
|
|
51
|
+
"default": "./dist/token-engine/index.js"
|
|
52
|
+
},
|
|
53
|
+
"require": {
|
|
54
|
+
"types": "./dist/token-engine/index.d.cts",
|
|
55
|
+
"default": "./dist/token-engine/index.cjs"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
48
58
|
"./l1": {
|
|
49
59
|
"import": {
|
|
50
60
|
"types": "./dist/l1/index.d.ts",
|