@unicitylabs/sphere-sdk 0.5.7 → 0.6.0-dev.1
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/dist/connect/index.cjs.map +1 -1
- package/dist/connect/index.js.map +1 -1
- package/dist/core/index.cjs +105 -11
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +39 -12
- package/dist/core/index.d.ts +39 -12
- package/dist/core/index.js +100 -10
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +191 -497
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +191 -497
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/browser/ipfs.cjs.map +1 -1
- package/dist/impl/browser/ipfs.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +203 -509
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.d.cts +10 -20
- package/dist/impl/nodejs/index.d.ts +10 -20
- package/dist/impl/nodejs/index.js +203 -509
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +116 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +40 -13
- package/dist/index.d.ts +40 -13
- package/dist/index.js +110 -11
- package/dist/index.js.map +1 -1
- package/dist/l1/index.cjs.map +1 -1
- package/dist/l1/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Token as Token$1 } from '@unicitylabs/state-transition-sdk/lib/token/Token';
|
|
2
2
|
import elliptic from 'elliptic';
|
|
3
|
-
export { areSameNametag, hashNametag, isPhoneNumber, normalizeNametag } from '@unicitylabs/nostr-js-sdk';
|
|
3
|
+
export { BindingInfo, ConnectionEventListener, IdentityBindingParams, NostrClient, NostrClientOptions, NostrKeyManager, areSameNametag, decryptNametag, encryptNametag, hashAddressForTag, hashNametag, isPhoneNumber, normalizeNametag } from '@unicitylabs/nostr-js-sdk';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Group Chat Types (NIP-29)
|
|
@@ -94,7 +94,7 @@ interface CreateGroupOptions {
|
|
|
94
94
|
* }
|
|
95
95
|
* ```
|
|
96
96
|
*/
|
|
97
|
-
type SphereErrorCode = 'NOT_INITIALIZED' | 'ALREADY_INITIALIZED' | 'INVALID_CONFIG' | 'INVALID_IDENTITY' | 'INSUFFICIENT_BALANCE' | 'INVALID_RECIPIENT' | 'TRANSFER_FAILED' | 'STORAGE_ERROR' | 'TRANSPORT_ERROR' | 'AGGREGATOR_ERROR' | 'VALIDATION_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT' | 'DECRYPTION_ERROR' | 'MODULE_NOT_AVAILABLE';
|
|
97
|
+
type SphereErrorCode = 'NOT_INITIALIZED' | 'ALREADY_INITIALIZED' | 'INVALID_CONFIG' | 'INVALID_IDENTITY' | 'INSUFFICIENT_BALANCE' | 'INVALID_RECIPIENT' | 'TRANSFER_FAILED' | 'STORAGE_ERROR' | 'TRANSPORT_ERROR' | 'AGGREGATOR_ERROR' | 'VALIDATION_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT' | 'DECRYPTION_ERROR' | 'MODULE_NOT_AVAILABLE' | 'SIGNING_ERROR';
|
|
98
98
|
declare class SphereError extends Error {
|
|
99
99
|
readonly code: SphereErrorCode;
|
|
100
100
|
readonly cause?: unknown;
|
|
@@ -241,6 +241,34 @@ declare function deriveAddressInfo(masterKey: MasterKey, basePath: string, index
|
|
|
241
241
|
* (L1 SDK compatibility)
|
|
242
242
|
*/
|
|
243
243
|
declare function generateAddressInfo(privateKey: string, index: number, path: string, prefix?: string): AddressInfo;
|
|
244
|
+
/** Prefix prepended to all signed messages (Bitcoin-like signed message format) */
|
|
245
|
+
declare const SIGN_MESSAGE_PREFIX = "Sphere Signed Message:\n";
|
|
246
|
+
/**
|
|
247
|
+
* Hash a message for signing using the Bitcoin-like double-SHA256 scheme:
|
|
248
|
+
* SHA256(SHA256(varint(prefix.length) + prefix + varint(msg.length) + msg))
|
|
249
|
+
*
|
|
250
|
+
* @returns 64-char lowercase hex hash
|
|
251
|
+
*/
|
|
252
|
+
declare function hashSignMessage(message: string): string;
|
|
253
|
+
/**
|
|
254
|
+
* Sign a message with a secp256k1 private key.
|
|
255
|
+
*
|
|
256
|
+
* Returns a 130-character hex string: v (2 chars) + r (64 chars) + s (64 chars).
|
|
257
|
+
* The recovery byte `v` is `31 + recoveryParam` (0-3).
|
|
258
|
+
*
|
|
259
|
+
* @param privateKeyHex - 64-char hex private key
|
|
260
|
+
* @param message - plaintext message to sign
|
|
261
|
+
*/
|
|
262
|
+
declare function signMessage(privateKeyHex: string, message: string): string;
|
|
263
|
+
/**
|
|
264
|
+
* Verify a signed message against a compressed secp256k1 public key.
|
|
265
|
+
*
|
|
266
|
+
* @param message - The original plaintext message
|
|
267
|
+
* @param signature - 130-char hex signature (v + r + s)
|
|
268
|
+
* @param expectedPubkey - 66-char compressed public key hex
|
|
269
|
+
* @returns `true` if the signature is valid and matches the expected public key
|
|
270
|
+
*/
|
|
271
|
+
declare function verifySignedMessage(message: string, signature: string, expectedPubkey: string): boolean;
|
|
244
272
|
|
|
245
273
|
/**
|
|
246
274
|
* TXF (Token eXchange Format) Type Definitions
|
|
@@ -1825,16 +1853,6 @@ interface TransportProvider extends BaseProvider {
|
|
|
1825
1853
|
* @returns true if successful, false if nametag is taken by another pubkey
|
|
1826
1854
|
*/
|
|
1827
1855
|
publishIdentityBinding?(chainPubkey: string, l1Address: string, directAddress: string, nametag?: string): Promise<boolean>;
|
|
1828
|
-
/**
|
|
1829
|
-
* @deprecated Use publishIdentityBinding instead
|
|
1830
|
-
* Register a nametag for this identity
|
|
1831
|
-
*/
|
|
1832
|
-
registerNametag?(nametag: string, chainPubkey: string, directAddress: string): Promise<boolean>;
|
|
1833
|
-
/**
|
|
1834
|
-
* @deprecated Use publishIdentityBinding instead
|
|
1835
|
-
* Publish nametag binding
|
|
1836
|
-
*/
|
|
1837
|
-
publishNametag?(nametag: string, address: string): Promise<void>;
|
|
1838
1856
|
/**
|
|
1839
1857
|
* Subscribe to broadcast messages (global/channel)
|
|
1840
1858
|
*/
|
|
@@ -4702,6 +4720,15 @@ declare class Sphere {
|
|
|
4702
4720
|
get identity(): Identity | null;
|
|
4703
4721
|
/** Is ready */
|
|
4704
4722
|
get isReady(): boolean;
|
|
4723
|
+
/**
|
|
4724
|
+
* Sign a plaintext message with the wallet's secp256k1 private key.
|
|
4725
|
+
*
|
|
4726
|
+
* Returns a 130-character hex string: v (2) + r (64) + s (64).
|
|
4727
|
+
* The private key never leaves the SDK boundary.
|
|
4728
|
+
*
|
|
4729
|
+
* @throws SphereError if the wallet is not initialized or identity is missing
|
|
4730
|
+
*/
|
|
4731
|
+
signMessage(message: string): string;
|
|
4705
4732
|
getStorage(): StorageProvider;
|
|
4706
4733
|
/**
|
|
4707
4734
|
* Get first token storage provider (for backward compatibility)
|
|
@@ -6865,4 +6892,4 @@ declare function getCoinIdBySymbol(symbol: string): string | undefined;
|
|
|
6865
6892
|
*/
|
|
6866
6893
|
declare function getCoinIdByName(name: string): string | undefined;
|
|
6867
6894
|
|
|
6868
|
-
export { type AddressInfo, type AddressMode, type AggregatorClient, type AggregatorEvent, type AggregatorEventCallback, type AggregatorEventType, type AggregatorProvider, type AggregatorProviderConfig, type Asset, type BackgroundProgressStatus, type BaseProvider, type BroadcastHandler, type BroadcastMessage, type BuildSplitBundleResult, type CMasterKeyData, COIN_TYPES, type CheckNetworkHealthOptions, CoinGeckoPriceProvider, type CombinedTransferBundleV6, CommunicationsModule, type CommunicationsModuleConfig, type CommunicationsModuleDependencies, type ComposingIndicator, type ConversationPage, type CreateGroupOptions, DEFAULT_AGGREGATOR_TIMEOUT, DEFAULT_AGGREGATOR_URL, DEFAULT_DERIVATION_PATH, DEFAULT_ELECTRUM_URL, DEFAULT_GROUP_RELAYS, DEFAULT_IPFS_BOOTSTRAP_PEERS, DEFAULT_IPFS_GATEWAYS, DEFAULT_MARKET_API_URL, DEFAULT_NOSTR_RELAYS, DEV_AGGREGATOR_URL, type DecryptionProgressCallback, type DerivationMode, type DirectMessage, type DirectTokenEntry, type DiscoverAddressProgress, type DiscoverAddressesOptions, type DiscoverAddressesResult, type DiscoveredAddress, type ExtendedValidationResult, type FullIdentity, type GetConversationPageOptions, GroupChatModule, type GroupChatModuleConfig, type GroupChatModuleDependencies, type GroupData, type GroupMemberData, type GroupMessageData, GroupRole, GroupVisibility, type HealthCheckFn, type Identity, type IdentityConfig, type InclusionProof, type IncomingBroadcast, type IncomingMessage, type IncomingPaymentRequest$1 as IncomingPaymentRequest, type IncomingTokenTransfer, type IncomingTransfer, type InitProgress, type InitProgressCallback, type InitProgressStep, type InstantSplitBundle, type InstantSplitBundleV4, type InstantSplitBundleV5, type InstantSplitOptions, type InstantSplitProcessResult, type InstantSplitResult, type InstantSplitV5RecoveryMetadata, type IntentStatus, type IntentType, type InvalidatedNametagEntry, index as L1, type L1Balance, L1PaymentsModule, type L1PaymentsModuleConfig, type L1PaymentsModuleDependencies, type L1SendRequest, type L1SendResult, type L1Transaction, type L1Utxo, LIMITS, type LegacyFileImportOptions, type LegacyFileInfo, type LegacyFileParseResult, type LegacyFileParsedData, type LegacyFileType, type LoadResult, type LogHandler, type LogLevel, type LoggerConfig, type LoggingConfig, type MarketIntent, MarketModule, type MarketModuleConfig, type MarketModuleDependencies, type MessageHandler, type MintOutboxEntry, type MintParams, type MintResult, NETWORKS, NIP29_KINDS, NOSTR_EVENT_KINDS, type NametagData, type NetworkHealthResult, type NetworkType, type OracleEvent, type OracleEventCallback, type OracleEventType, type OracleProvider, type OutboxEntry, type OutgoingPaymentRequest, type ParsedStorageData, type PaymentRequest, type PaymentRequestHandler$1 as PaymentRequestHandler, type PaymentRequestResponse, type PaymentRequestResponseHandler$1 as PaymentRequestResponseHandler, type PaymentRequestResponseType$1 as PaymentRequestResponseType, type PaymentRequestResult, type PaymentRequestStatus, type PaymentSession, type PaymentSessionDirection, type PaymentSessionError, type PaymentSessionErrorCode, type PaymentSessionStatus, PaymentsModule, type PaymentsModuleConfig, type PaymentsModuleDependencies, type PeerInfo, type PendingV5Finalization, type PostIntentRequest, type PostIntentResult, type PricePlatform, type PriceProvider, type PriceProviderConfig, type ProviderMetadata, type ProviderRole, type ProviderStatus, type ProviderStatusInfo, type ReceiveOptions, type ReceiveResult, type RegistryNetwork, STORAGE_KEYS, STORAGE_KEYS_ADDRESS, STORAGE_KEYS_GLOBAL, STORAGE_PREFIX, type SaveResult, type ScanAddressProgress, type ScanAddressesOptions, type ScanAddressesResult, type ScannedAddressResult, type SearchFilters, type SearchIntentResult, type SearchOptions, type SearchResult, type ServiceHealthResult, type SpentTokenInfo, type SpentTokenResult, Sphere, type SphereConfig, type SphereCreateOptions, SphereError, type SphereErrorCode, type SphereEventHandler, type SphereEventMap, type SphereEventType, type SphereImportOptions, type SphereInitOptions, type SphereInitResult, type SphereLoadOptions, type SphereStatus, type SplitPaymentSession, type SplitRecoveryResult, type StorageEvent, type StorageEventCallback, type StorageEventType, type StorageProvider, type StorageProviderConfig, type SubmitResult, type SyncResult, TEST_AGGREGATOR_URL, TEST_ELECTRUM_URL, TEST_NOSTR_RELAYS, TIMEOUTS, type Token, type TokenDefinition, type TokenIcon, type TokenPrice, TokenRegistry, type TokenState, type TokenStatus, type TokenStorageProvider, type TokenTransferDetail, type TokenTransferHandler, type TokenTransferPayload, type ValidationResult as TokenValidationResult, TokenValidator, type TombstoneEntry, type TrackedAddress, type TrackedAddressEntry, type TransactionHistoryEntry, type TransferCommitment, type TransferMode, type TransferRequest, type TransferResult, type TransferStatus, type TransportEvent, type TransportEventCallback, type TransportEventType, type TransportProvider, type TransportProviderConfig, type TrustBaseLoader, type TxfAuthenticator, type TxfGenesis, type TxfGenesisData, type TxfInclusionProof, type TxfIntegrity, type TxfInvalidEntry, type TxfMerkleStep, type TxfMerkleTreePath, type TxfMeta, type TxfOutboxEntry, type TxfSentEntry, type TxfState, type TxfStorageData, type TxfStorageDataBase, type TxfToken, type TxfTombstone, type TxfTransaction, type UnconfirmedResolutionResult, type V5FinalizationStage, type ValidationAction, type ValidationIssue, type ValidationResult$1 as ValidationResult, type WaitOptions, type WalletDatInfo, type WalletInfo, type WalletJSON$1 as WalletJSON, type WalletJSONExportOptions$1 as WalletJSONExportOptions, type WalletSource, archivedKeyFromTokenId, base58Decode, base58Encode, buildTxfStorageData, bytesToHex, checkNetworkHealth, countCommittedTransactions, createAddress, createCommunicationsModule, createGroupChatModule, createKeyPair, createL1PaymentsModule, createMarketModule, createPaymentSession, createPaymentSessionError, createPaymentsModule, createPriceProvider, createSphere, createSplitPaymentSession, createTokenValidator, decodeBech32, decryptCMasterKey, decryptPrivateKey, decryptTextFormatKey, deriveAddressInfo, deriveChildKey$1 as deriveChildKey, deriveKeyAtPath$1 as deriveKeyAtPath, doubleSha256, encodeBech32, extractFromText, findPattern, forkedKeyFromTokenIdAndState, formatAmount, generateMasterKey, generateMnemonic, getAddressHrp, getAddressId, getAddressStorageKey, getCoinIdByName, getCoinIdBySymbol, getCurrentStateHash, getPublicKey, getSphere, getTokenDecimals, getTokenDefinition, getTokenIconUrl, getTokenId, getTokenName, getTokenSymbol, hasMissingNewStateHash, hasUncommittedTransactions, hasValidTxfData, hash160, hexToBytes, identityFromMnemonicSync, initSphere, isArchivedKey, isCombinedTransferBundleV6, isForkedKey, isInstantSplitBundle, isInstantSplitBundleV4, isInstantSplitBundleV5, isKnownToken, isPaymentSessionTerminal, isPaymentSessionTimedOut, isSQLiteDatabase, isSphereError, isTextWalletEncrypted, isTokenKey, isValidBech32, isValidNametag, isValidPrivateKey, isValidTokenId, isWalletDatEncrypted, isWalletTextFormat, keyFromTokenId, loadSphere, logger, mnemonicToSeedSync, normalizeSdkTokenToStorage, objectToTxf, parseAndDecryptWalletDat, parseAndDecryptWalletText, parseForkedKey, parseTxfStorageData, parseWalletDat, parseWalletText, randomBytes, randomHex, randomUUID, ripemd160, sha256, sleep, sphereExists, toHumanReadable, toSmallestUnit, tokenIdFromArchivedKey, tokenIdFromKey, tokenToTxf, txfToToken, validateMnemonic };
|
|
6895
|
+
export { type AddressInfo, type AddressMode, type AggregatorClient, type AggregatorEvent, type AggregatorEventCallback, type AggregatorEventType, type AggregatorProvider, type AggregatorProviderConfig, type Asset, type BackgroundProgressStatus, type BaseProvider, type BroadcastHandler, type BroadcastMessage, type BuildSplitBundleResult, type CMasterKeyData, COIN_TYPES, type CheckNetworkHealthOptions, CoinGeckoPriceProvider, type CombinedTransferBundleV6, CommunicationsModule, type CommunicationsModuleConfig, type CommunicationsModuleDependencies, type ComposingIndicator, type ConversationPage, type CreateGroupOptions, DEFAULT_AGGREGATOR_TIMEOUT, DEFAULT_AGGREGATOR_URL, DEFAULT_DERIVATION_PATH, DEFAULT_ELECTRUM_URL, DEFAULT_GROUP_RELAYS, DEFAULT_IPFS_BOOTSTRAP_PEERS, DEFAULT_IPFS_GATEWAYS, DEFAULT_MARKET_API_URL, DEFAULT_NOSTR_RELAYS, DEV_AGGREGATOR_URL, type DecryptionProgressCallback, type DerivationMode, type DirectMessage, type DirectTokenEntry, type DiscoverAddressProgress, type DiscoverAddressesOptions, type DiscoverAddressesResult, type DiscoveredAddress, type ExtendedValidationResult, type FullIdentity, type GetConversationPageOptions, GroupChatModule, type GroupChatModuleConfig, type GroupChatModuleDependencies, type GroupData, type GroupMemberData, type GroupMessageData, GroupRole, GroupVisibility, type HealthCheckFn, type Identity, type IdentityConfig, type InclusionProof, type IncomingBroadcast, type IncomingMessage, type IncomingPaymentRequest$1 as IncomingPaymentRequest, type IncomingTokenTransfer, type IncomingTransfer, type InitProgress, type InitProgressCallback, type InitProgressStep, type InstantSplitBundle, type InstantSplitBundleV4, type InstantSplitBundleV5, type InstantSplitOptions, type InstantSplitProcessResult, type InstantSplitResult, type InstantSplitV5RecoveryMetadata, type IntentStatus, type IntentType, type InvalidatedNametagEntry, index as L1, type L1Balance, L1PaymentsModule, type L1PaymentsModuleConfig, type L1PaymentsModuleDependencies, type L1SendRequest, type L1SendResult, type L1Transaction, type L1Utxo, LIMITS, type LegacyFileImportOptions, type LegacyFileInfo, type LegacyFileParseResult, type LegacyFileParsedData, type LegacyFileType, type LoadResult, type LogHandler, type LogLevel, type LoggerConfig, type LoggingConfig, type MarketIntent, MarketModule, type MarketModuleConfig, type MarketModuleDependencies, type MessageHandler, type MintOutboxEntry, type MintParams, type MintResult, NETWORKS, NIP29_KINDS, NOSTR_EVENT_KINDS, type NametagData, type NetworkHealthResult, type NetworkType, type OracleEvent, type OracleEventCallback, type OracleEventType, type OracleProvider, type OutboxEntry, type OutgoingPaymentRequest, type ParsedStorageData, type PaymentRequest, type PaymentRequestHandler$1 as PaymentRequestHandler, type PaymentRequestResponse, type PaymentRequestResponseHandler$1 as PaymentRequestResponseHandler, type PaymentRequestResponseType$1 as PaymentRequestResponseType, type PaymentRequestResult, type PaymentRequestStatus, type PaymentSession, type PaymentSessionDirection, type PaymentSessionError, type PaymentSessionErrorCode, type PaymentSessionStatus, PaymentsModule, type PaymentsModuleConfig, type PaymentsModuleDependencies, type PeerInfo, type PendingV5Finalization, type PostIntentRequest, type PostIntentResult, type PricePlatform, type PriceProvider, type PriceProviderConfig, type ProviderMetadata, type ProviderRole, type ProviderStatus, type ProviderStatusInfo, type ReceiveOptions, type ReceiveResult, type RegistryNetwork, SIGN_MESSAGE_PREFIX, STORAGE_KEYS, STORAGE_KEYS_ADDRESS, STORAGE_KEYS_GLOBAL, STORAGE_PREFIX, type SaveResult, type ScanAddressProgress, type ScanAddressesOptions, type ScanAddressesResult, type ScannedAddressResult, type SearchFilters, type SearchIntentResult, type SearchOptions, type SearchResult, type ServiceHealthResult, type SpentTokenInfo, type SpentTokenResult, Sphere, type SphereConfig, type SphereCreateOptions, SphereError, type SphereErrorCode, type SphereEventHandler, type SphereEventMap, type SphereEventType, type SphereImportOptions, type SphereInitOptions, type SphereInitResult, type SphereLoadOptions, type SphereStatus, type SplitPaymentSession, type SplitRecoveryResult, type StorageEvent, type StorageEventCallback, type StorageEventType, type StorageProvider, type StorageProviderConfig, type SubmitResult, type SyncResult, TEST_AGGREGATOR_URL, TEST_ELECTRUM_URL, TEST_NOSTR_RELAYS, TIMEOUTS, type Token, type TokenDefinition, type TokenIcon, type TokenPrice, TokenRegistry, type TokenState, type TokenStatus, type TokenStorageProvider, type TokenTransferDetail, type TokenTransferHandler, type TokenTransferPayload, type ValidationResult as TokenValidationResult, TokenValidator, type TombstoneEntry, type TrackedAddress, type TrackedAddressEntry, type TransactionHistoryEntry, type TransferCommitment, type TransferMode, type TransferRequest, type TransferResult, type TransferStatus, type TransportEvent, type TransportEventCallback, type TransportEventType, type TransportProvider, type TransportProviderConfig, type TrustBaseLoader, type TxfAuthenticator, type TxfGenesis, type TxfGenesisData, type TxfInclusionProof, type TxfIntegrity, type TxfInvalidEntry, type TxfMerkleStep, type TxfMerkleTreePath, type TxfMeta, type TxfOutboxEntry, type TxfSentEntry, type TxfState, type TxfStorageData, type TxfStorageDataBase, type TxfToken, type TxfTombstone, type TxfTransaction, type UnconfirmedResolutionResult, type V5FinalizationStage, type ValidationAction, type ValidationIssue, type ValidationResult$1 as ValidationResult, type WaitOptions, type WalletDatInfo, type WalletInfo, type WalletJSON$1 as WalletJSON, type WalletJSONExportOptions$1 as WalletJSONExportOptions, type WalletSource, archivedKeyFromTokenId, base58Decode, base58Encode, buildTxfStorageData, bytesToHex, checkNetworkHealth, countCommittedTransactions, createAddress, createCommunicationsModule, createGroupChatModule, createKeyPair, createL1PaymentsModule, createMarketModule, createPaymentSession, createPaymentSessionError, createPaymentsModule, createPriceProvider, createSphere, createSplitPaymentSession, createTokenValidator, decodeBech32, decryptCMasterKey, decryptPrivateKey, decryptTextFormatKey, deriveAddressInfo, deriveChildKey$1 as deriveChildKey, deriveKeyAtPath$1 as deriveKeyAtPath, doubleSha256, encodeBech32, extractFromText, findPattern, forkedKeyFromTokenIdAndState, formatAmount, generateMasterKey, generateMnemonic, getAddressHrp, getAddressId, getAddressStorageKey, getCoinIdByName, getCoinIdBySymbol, getCurrentStateHash, getPublicKey, getSphere, getTokenDecimals, getTokenDefinition, getTokenIconUrl, getTokenId, getTokenName, getTokenSymbol, hasMissingNewStateHash, hasUncommittedTransactions, hasValidTxfData, hash160, hashSignMessage, hexToBytes, identityFromMnemonicSync, initSphere, isArchivedKey, isCombinedTransferBundleV6, isForkedKey, isInstantSplitBundle, isInstantSplitBundleV4, isInstantSplitBundleV5, isKnownToken, isPaymentSessionTerminal, isPaymentSessionTimedOut, isSQLiteDatabase, isSphereError, isTextWalletEncrypted, isTokenKey, isValidBech32, isValidNametag, isValidPrivateKey, isValidTokenId, isWalletDatEncrypted, isWalletTextFormat, keyFromTokenId, loadSphere, logger, mnemonicToSeedSync, normalizeSdkTokenToStorage, objectToTxf, parseAndDecryptWalletDat, parseAndDecryptWalletText, parseForkedKey, parseTxfStorageData, parseWalletDat, parseWalletText, randomBytes, randomHex, randomUUID, ripemd160, sha256, signMessage, sleep, sphereExists, toHumanReadable, toSmallestUnit, tokenIdFromArchivedKey, tokenIdFromKey, tokenToTxf, txfToToken, validateMnemonic, verifySignedMessage };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Token as Token$1 } from '@unicitylabs/state-transition-sdk/lib/token/Token';
|
|
2
2
|
import elliptic from 'elliptic';
|
|
3
|
-
export { areSameNametag, hashNametag, isPhoneNumber, normalizeNametag } from '@unicitylabs/nostr-js-sdk';
|
|
3
|
+
export { BindingInfo, ConnectionEventListener, IdentityBindingParams, NostrClient, NostrClientOptions, NostrKeyManager, areSameNametag, decryptNametag, encryptNametag, hashAddressForTag, hashNametag, isPhoneNumber, normalizeNametag } from '@unicitylabs/nostr-js-sdk';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Group Chat Types (NIP-29)
|
|
@@ -94,7 +94,7 @@ interface CreateGroupOptions {
|
|
|
94
94
|
* }
|
|
95
95
|
* ```
|
|
96
96
|
*/
|
|
97
|
-
type SphereErrorCode = 'NOT_INITIALIZED' | 'ALREADY_INITIALIZED' | 'INVALID_CONFIG' | 'INVALID_IDENTITY' | 'INSUFFICIENT_BALANCE' | 'INVALID_RECIPIENT' | 'TRANSFER_FAILED' | 'STORAGE_ERROR' | 'TRANSPORT_ERROR' | 'AGGREGATOR_ERROR' | 'VALIDATION_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT' | 'DECRYPTION_ERROR' | 'MODULE_NOT_AVAILABLE';
|
|
97
|
+
type SphereErrorCode = 'NOT_INITIALIZED' | 'ALREADY_INITIALIZED' | 'INVALID_CONFIG' | 'INVALID_IDENTITY' | 'INSUFFICIENT_BALANCE' | 'INVALID_RECIPIENT' | 'TRANSFER_FAILED' | 'STORAGE_ERROR' | 'TRANSPORT_ERROR' | 'AGGREGATOR_ERROR' | 'VALIDATION_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT' | 'DECRYPTION_ERROR' | 'MODULE_NOT_AVAILABLE' | 'SIGNING_ERROR';
|
|
98
98
|
declare class SphereError extends Error {
|
|
99
99
|
readonly code: SphereErrorCode;
|
|
100
100
|
readonly cause?: unknown;
|
|
@@ -241,6 +241,34 @@ declare function deriveAddressInfo(masterKey: MasterKey, basePath: string, index
|
|
|
241
241
|
* (L1 SDK compatibility)
|
|
242
242
|
*/
|
|
243
243
|
declare function generateAddressInfo(privateKey: string, index: number, path: string, prefix?: string): AddressInfo;
|
|
244
|
+
/** Prefix prepended to all signed messages (Bitcoin-like signed message format) */
|
|
245
|
+
declare const SIGN_MESSAGE_PREFIX = "Sphere Signed Message:\n";
|
|
246
|
+
/**
|
|
247
|
+
* Hash a message for signing using the Bitcoin-like double-SHA256 scheme:
|
|
248
|
+
* SHA256(SHA256(varint(prefix.length) + prefix + varint(msg.length) + msg))
|
|
249
|
+
*
|
|
250
|
+
* @returns 64-char lowercase hex hash
|
|
251
|
+
*/
|
|
252
|
+
declare function hashSignMessage(message: string): string;
|
|
253
|
+
/**
|
|
254
|
+
* Sign a message with a secp256k1 private key.
|
|
255
|
+
*
|
|
256
|
+
* Returns a 130-character hex string: v (2 chars) + r (64 chars) + s (64 chars).
|
|
257
|
+
* The recovery byte `v` is `31 + recoveryParam` (0-3).
|
|
258
|
+
*
|
|
259
|
+
* @param privateKeyHex - 64-char hex private key
|
|
260
|
+
* @param message - plaintext message to sign
|
|
261
|
+
*/
|
|
262
|
+
declare function signMessage(privateKeyHex: string, message: string): string;
|
|
263
|
+
/**
|
|
264
|
+
* Verify a signed message against a compressed secp256k1 public key.
|
|
265
|
+
*
|
|
266
|
+
* @param message - The original plaintext message
|
|
267
|
+
* @param signature - 130-char hex signature (v + r + s)
|
|
268
|
+
* @param expectedPubkey - 66-char compressed public key hex
|
|
269
|
+
* @returns `true` if the signature is valid and matches the expected public key
|
|
270
|
+
*/
|
|
271
|
+
declare function verifySignedMessage(message: string, signature: string, expectedPubkey: string): boolean;
|
|
244
272
|
|
|
245
273
|
/**
|
|
246
274
|
* TXF (Token eXchange Format) Type Definitions
|
|
@@ -1825,16 +1853,6 @@ interface TransportProvider extends BaseProvider {
|
|
|
1825
1853
|
* @returns true if successful, false if nametag is taken by another pubkey
|
|
1826
1854
|
*/
|
|
1827
1855
|
publishIdentityBinding?(chainPubkey: string, l1Address: string, directAddress: string, nametag?: string): Promise<boolean>;
|
|
1828
|
-
/**
|
|
1829
|
-
* @deprecated Use publishIdentityBinding instead
|
|
1830
|
-
* Register a nametag for this identity
|
|
1831
|
-
*/
|
|
1832
|
-
registerNametag?(nametag: string, chainPubkey: string, directAddress: string): Promise<boolean>;
|
|
1833
|
-
/**
|
|
1834
|
-
* @deprecated Use publishIdentityBinding instead
|
|
1835
|
-
* Publish nametag binding
|
|
1836
|
-
*/
|
|
1837
|
-
publishNametag?(nametag: string, address: string): Promise<void>;
|
|
1838
1856
|
/**
|
|
1839
1857
|
* Subscribe to broadcast messages (global/channel)
|
|
1840
1858
|
*/
|
|
@@ -4702,6 +4720,15 @@ declare class Sphere {
|
|
|
4702
4720
|
get identity(): Identity | null;
|
|
4703
4721
|
/** Is ready */
|
|
4704
4722
|
get isReady(): boolean;
|
|
4723
|
+
/**
|
|
4724
|
+
* Sign a plaintext message with the wallet's secp256k1 private key.
|
|
4725
|
+
*
|
|
4726
|
+
* Returns a 130-character hex string: v (2) + r (64) + s (64).
|
|
4727
|
+
* The private key never leaves the SDK boundary.
|
|
4728
|
+
*
|
|
4729
|
+
* @throws SphereError if the wallet is not initialized or identity is missing
|
|
4730
|
+
*/
|
|
4731
|
+
signMessage(message: string): string;
|
|
4705
4732
|
getStorage(): StorageProvider;
|
|
4706
4733
|
/**
|
|
4707
4734
|
* Get first token storage provider (for backward compatibility)
|
|
@@ -6865,4 +6892,4 @@ declare function getCoinIdBySymbol(symbol: string): string | undefined;
|
|
|
6865
6892
|
*/
|
|
6866
6893
|
declare function getCoinIdByName(name: string): string | undefined;
|
|
6867
6894
|
|
|
6868
|
-
export { type AddressInfo, type AddressMode, type AggregatorClient, type AggregatorEvent, type AggregatorEventCallback, type AggregatorEventType, type AggregatorProvider, type AggregatorProviderConfig, type Asset, type BackgroundProgressStatus, type BaseProvider, type BroadcastHandler, type BroadcastMessage, type BuildSplitBundleResult, type CMasterKeyData, COIN_TYPES, type CheckNetworkHealthOptions, CoinGeckoPriceProvider, type CombinedTransferBundleV6, CommunicationsModule, type CommunicationsModuleConfig, type CommunicationsModuleDependencies, type ComposingIndicator, type ConversationPage, type CreateGroupOptions, DEFAULT_AGGREGATOR_TIMEOUT, DEFAULT_AGGREGATOR_URL, DEFAULT_DERIVATION_PATH, DEFAULT_ELECTRUM_URL, DEFAULT_GROUP_RELAYS, DEFAULT_IPFS_BOOTSTRAP_PEERS, DEFAULT_IPFS_GATEWAYS, DEFAULT_MARKET_API_URL, DEFAULT_NOSTR_RELAYS, DEV_AGGREGATOR_URL, type DecryptionProgressCallback, type DerivationMode, type DirectMessage, type DirectTokenEntry, type DiscoverAddressProgress, type DiscoverAddressesOptions, type DiscoverAddressesResult, type DiscoveredAddress, type ExtendedValidationResult, type FullIdentity, type GetConversationPageOptions, GroupChatModule, type GroupChatModuleConfig, type GroupChatModuleDependencies, type GroupData, type GroupMemberData, type GroupMessageData, GroupRole, GroupVisibility, type HealthCheckFn, type Identity, type IdentityConfig, type InclusionProof, type IncomingBroadcast, type IncomingMessage, type IncomingPaymentRequest$1 as IncomingPaymentRequest, type IncomingTokenTransfer, type IncomingTransfer, type InitProgress, type InitProgressCallback, type InitProgressStep, type InstantSplitBundle, type InstantSplitBundleV4, type InstantSplitBundleV5, type InstantSplitOptions, type InstantSplitProcessResult, type InstantSplitResult, type InstantSplitV5RecoveryMetadata, type IntentStatus, type IntentType, type InvalidatedNametagEntry, index as L1, type L1Balance, L1PaymentsModule, type L1PaymentsModuleConfig, type L1PaymentsModuleDependencies, type L1SendRequest, type L1SendResult, type L1Transaction, type L1Utxo, LIMITS, type LegacyFileImportOptions, type LegacyFileInfo, type LegacyFileParseResult, type LegacyFileParsedData, type LegacyFileType, type LoadResult, type LogHandler, type LogLevel, type LoggerConfig, type LoggingConfig, type MarketIntent, MarketModule, type MarketModuleConfig, type MarketModuleDependencies, type MessageHandler, type MintOutboxEntry, type MintParams, type MintResult, NETWORKS, NIP29_KINDS, NOSTR_EVENT_KINDS, type NametagData, type NetworkHealthResult, type NetworkType, type OracleEvent, type OracleEventCallback, type OracleEventType, type OracleProvider, type OutboxEntry, type OutgoingPaymentRequest, type ParsedStorageData, type PaymentRequest, type PaymentRequestHandler$1 as PaymentRequestHandler, type PaymentRequestResponse, type PaymentRequestResponseHandler$1 as PaymentRequestResponseHandler, type PaymentRequestResponseType$1 as PaymentRequestResponseType, type PaymentRequestResult, type PaymentRequestStatus, type PaymentSession, type PaymentSessionDirection, type PaymentSessionError, type PaymentSessionErrorCode, type PaymentSessionStatus, PaymentsModule, type PaymentsModuleConfig, type PaymentsModuleDependencies, type PeerInfo, type PendingV5Finalization, type PostIntentRequest, type PostIntentResult, type PricePlatform, type PriceProvider, type PriceProviderConfig, type ProviderMetadata, type ProviderRole, type ProviderStatus, type ProviderStatusInfo, type ReceiveOptions, type ReceiveResult, type RegistryNetwork, STORAGE_KEYS, STORAGE_KEYS_ADDRESS, STORAGE_KEYS_GLOBAL, STORAGE_PREFIX, type SaveResult, type ScanAddressProgress, type ScanAddressesOptions, type ScanAddressesResult, type ScannedAddressResult, type SearchFilters, type SearchIntentResult, type SearchOptions, type SearchResult, type ServiceHealthResult, type SpentTokenInfo, type SpentTokenResult, Sphere, type SphereConfig, type SphereCreateOptions, SphereError, type SphereErrorCode, type SphereEventHandler, type SphereEventMap, type SphereEventType, type SphereImportOptions, type SphereInitOptions, type SphereInitResult, type SphereLoadOptions, type SphereStatus, type SplitPaymentSession, type SplitRecoveryResult, type StorageEvent, type StorageEventCallback, type StorageEventType, type StorageProvider, type StorageProviderConfig, type SubmitResult, type SyncResult, TEST_AGGREGATOR_URL, TEST_ELECTRUM_URL, TEST_NOSTR_RELAYS, TIMEOUTS, type Token, type TokenDefinition, type TokenIcon, type TokenPrice, TokenRegistry, type TokenState, type TokenStatus, type TokenStorageProvider, type TokenTransferDetail, type TokenTransferHandler, type TokenTransferPayload, type ValidationResult as TokenValidationResult, TokenValidator, type TombstoneEntry, type TrackedAddress, type TrackedAddressEntry, type TransactionHistoryEntry, type TransferCommitment, type TransferMode, type TransferRequest, type TransferResult, type TransferStatus, type TransportEvent, type TransportEventCallback, type TransportEventType, type TransportProvider, type TransportProviderConfig, type TrustBaseLoader, type TxfAuthenticator, type TxfGenesis, type TxfGenesisData, type TxfInclusionProof, type TxfIntegrity, type TxfInvalidEntry, type TxfMerkleStep, type TxfMerkleTreePath, type TxfMeta, type TxfOutboxEntry, type TxfSentEntry, type TxfState, type TxfStorageData, type TxfStorageDataBase, type TxfToken, type TxfTombstone, type TxfTransaction, type UnconfirmedResolutionResult, type V5FinalizationStage, type ValidationAction, type ValidationIssue, type ValidationResult$1 as ValidationResult, type WaitOptions, type WalletDatInfo, type WalletInfo, type WalletJSON$1 as WalletJSON, type WalletJSONExportOptions$1 as WalletJSONExportOptions, type WalletSource, archivedKeyFromTokenId, base58Decode, base58Encode, buildTxfStorageData, bytesToHex, checkNetworkHealth, countCommittedTransactions, createAddress, createCommunicationsModule, createGroupChatModule, createKeyPair, createL1PaymentsModule, createMarketModule, createPaymentSession, createPaymentSessionError, createPaymentsModule, createPriceProvider, createSphere, createSplitPaymentSession, createTokenValidator, decodeBech32, decryptCMasterKey, decryptPrivateKey, decryptTextFormatKey, deriveAddressInfo, deriveChildKey$1 as deriveChildKey, deriveKeyAtPath$1 as deriveKeyAtPath, doubleSha256, encodeBech32, extractFromText, findPattern, forkedKeyFromTokenIdAndState, formatAmount, generateMasterKey, generateMnemonic, getAddressHrp, getAddressId, getAddressStorageKey, getCoinIdByName, getCoinIdBySymbol, getCurrentStateHash, getPublicKey, getSphere, getTokenDecimals, getTokenDefinition, getTokenIconUrl, getTokenId, getTokenName, getTokenSymbol, hasMissingNewStateHash, hasUncommittedTransactions, hasValidTxfData, hash160, hexToBytes, identityFromMnemonicSync, initSphere, isArchivedKey, isCombinedTransferBundleV6, isForkedKey, isInstantSplitBundle, isInstantSplitBundleV4, isInstantSplitBundleV5, isKnownToken, isPaymentSessionTerminal, isPaymentSessionTimedOut, isSQLiteDatabase, isSphereError, isTextWalletEncrypted, isTokenKey, isValidBech32, isValidNametag, isValidPrivateKey, isValidTokenId, isWalletDatEncrypted, isWalletTextFormat, keyFromTokenId, loadSphere, logger, mnemonicToSeedSync, normalizeSdkTokenToStorage, objectToTxf, parseAndDecryptWalletDat, parseAndDecryptWalletText, parseForkedKey, parseTxfStorageData, parseWalletDat, parseWalletText, randomBytes, randomHex, randomUUID, ripemd160, sha256, sleep, sphereExists, toHumanReadable, toSmallestUnit, tokenIdFromArchivedKey, tokenIdFromKey, tokenToTxf, txfToToken, validateMnemonic };
|
|
6895
|
+
export { type AddressInfo, type AddressMode, type AggregatorClient, type AggregatorEvent, type AggregatorEventCallback, type AggregatorEventType, type AggregatorProvider, type AggregatorProviderConfig, type Asset, type BackgroundProgressStatus, type BaseProvider, type BroadcastHandler, type BroadcastMessage, type BuildSplitBundleResult, type CMasterKeyData, COIN_TYPES, type CheckNetworkHealthOptions, CoinGeckoPriceProvider, type CombinedTransferBundleV6, CommunicationsModule, type CommunicationsModuleConfig, type CommunicationsModuleDependencies, type ComposingIndicator, type ConversationPage, type CreateGroupOptions, DEFAULT_AGGREGATOR_TIMEOUT, DEFAULT_AGGREGATOR_URL, DEFAULT_DERIVATION_PATH, DEFAULT_ELECTRUM_URL, DEFAULT_GROUP_RELAYS, DEFAULT_IPFS_BOOTSTRAP_PEERS, DEFAULT_IPFS_GATEWAYS, DEFAULT_MARKET_API_URL, DEFAULT_NOSTR_RELAYS, DEV_AGGREGATOR_URL, type DecryptionProgressCallback, type DerivationMode, type DirectMessage, type DirectTokenEntry, type DiscoverAddressProgress, type DiscoverAddressesOptions, type DiscoverAddressesResult, type DiscoveredAddress, type ExtendedValidationResult, type FullIdentity, type GetConversationPageOptions, GroupChatModule, type GroupChatModuleConfig, type GroupChatModuleDependencies, type GroupData, type GroupMemberData, type GroupMessageData, GroupRole, GroupVisibility, type HealthCheckFn, type Identity, type IdentityConfig, type InclusionProof, type IncomingBroadcast, type IncomingMessage, type IncomingPaymentRequest$1 as IncomingPaymentRequest, type IncomingTokenTransfer, type IncomingTransfer, type InitProgress, type InitProgressCallback, type InitProgressStep, type InstantSplitBundle, type InstantSplitBundleV4, type InstantSplitBundleV5, type InstantSplitOptions, type InstantSplitProcessResult, type InstantSplitResult, type InstantSplitV5RecoveryMetadata, type IntentStatus, type IntentType, type InvalidatedNametagEntry, index as L1, type L1Balance, L1PaymentsModule, type L1PaymentsModuleConfig, type L1PaymentsModuleDependencies, type L1SendRequest, type L1SendResult, type L1Transaction, type L1Utxo, LIMITS, type LegacyFileImportOptions, type LegacyFileInfo, type LegacyFileParseResult, type LegacyFileParsedData, type LegacyFileType, type LoadResult, type LogHandler, type LogLevel, type LoggerConfig, type LoggingConfig, type MarketIntent, MarketModule, type MarketModuleConfig, type MarketModuleDependencies, type MessageHandler, type MintOutboxEntry, type MintParams, type MintResult, NETWORKS, NIP29_KINDS, NOSTR_EVENT_KINDS, type NametagData, type NetworkHealthResult, type NetworkType, type OracleEvent, type OracleEventCallback, type OracleEventType, type OracleProvider, type OutboxEntry, type OutgoingPaymentRequest, type ParsedStorageData, type PaymentRequest, type PaymentRequestHandler$1 as PaymentRequestHandler, type PaymentRequestResponse, type PaymentRequestResponseHandler$1 as PaymentRequestResponseHandler, type PaymentRequestResponseType$1 as PaymentRequestResponseType, type PaymentRequestResult, type PaymentRequestStatus, type PaymentSession, type PaymentSessionDirection, type PaymentSessionError, type PaymentSessionErrorCode, type PaymentSessionStatus, PaymentsModule, type PaymentsModuleConfig, type PaymentsModuleDependencies, type PeerInfo, type PendingV5Finalization, type PostIntentRequest, type PostIntentResult, type PricePlatform, type PriceProvider, type PriceProviderConfig, type ProviderMetadata, type ProviderRole, type ProviderStatus, type ProviderStatusInfo, type ReceiveOptions, type ReceiveResult, type RegistryNetwork, SIGN_MESSAGE_PREFIX, STORAGE_KEYS, STORAGE_KEYS_ADDRESS, STORAGE_KEYS_GLOBAL, STORAGE_PREFIX, type SaveResult, type ScanAddressProgress, type ScanAddressesOptions, type ScanAddressesResult, type ScannedAddressResult, type SearchFilters, type SearchIntentResult, type SearchOptions, type SearchResult, type ServiceHealthResult, type SpentTokenInfo, type SpentTokenResult, Sphere, type SphereConfig, type SphereCreateOptions, SphereError, type SphereErrorCode, type SphereEventHandler, type SphereEventMap, type SphereEventType, type SphereImportOptions, type SphereInitOptions, type SphereInitResult, type SphereLoadOptions, type SphereStatus, type SplitPaymentSession, type SplitRecoveryResult, type StorageEvent, type StorageEventCallback, type StorageEventType, type StorageProvider, type StorageProviderConfig, type SubmitResult, type SyncResult, TEST_AGGREGATOR_URL, TEST_ELECTRUM_URL, TEST_NOSTR_RELAYS, TIMEOUTS, type Token, type TokenDefinition, type TokenIcon, type TokenPrice, TokenRegistry, type TokenState, type TokenStatus, type TokenStorageProvider, type TokenTransferDetail, type TokenTransferHandler, type TokenTransferPayload, type ValidationResult as TokenValidationResult, TokenValidator, type TombstoneEntry, type TrackedAddress, type TrackedAddressEntry, type TransactionHistoryEntry, type TransferCommitment, type TransferMode, type TransferRequest, type TransferResult, type TransferStatus, type TransportEvent, type TransportEventCallback, type TransportEventType, type TransportProvider, type TransportProviderConfig, type TrustBaseLoader, type TxfAuthenticator, type TxfGenesis, type TxfGenesisData, type TxfInclusionProof, type TxfIntegrity, type TxfInvalidEntry, type TxfMerkleStep, type TxfMerkleTreePath, type TxfMeta, type TxfOutboxEntry, type TxfSentEntry, type TxfState, type TxfStorageData, type TxfStorageDataBase, type TxfToken, type TxfTombstone, type TxfTransaction, type UnconfirmedResolutionResult, type V5FinalizationStage, type ValidationAction, type ValidationIssue, type ValidationResult$1 as ValidationResult, type WaitOptions, type WalletDatInfo, type WalletInfo, type WalletJSON$1 as WalletJSON, type WalletJSONExportOptions$1 as WalletJSONExportOptions, type WalletSource, archivedKeyFromTokenId, base58Decode, base58Encode, buildTxfStorageData, bytesToHex, checkNetworkHealth, countCommittedTransactions, createAddress, createCommunicationsModule, createGroupChatModule, createKeyPair, createL1PaymentsModule, createMarketModule, createPaymentSession, createPaymentSessionError, createPaymentsModule, createPriceProvider, createSphere, createSplitPaymentSession, createTokenValidator, decodeBech32, decryptCMasterKey, decryptPrivateKey, decryptTextFormatKey, deriveAddressInfo, deriveChildKey$1 as deriveChildKey, deriveKeyAtPath$1 as deriveKeyAtPath, doubleSha256, encodeBech32, extractFromText, findPattern, forkedKeyFromTokenIdAndState, formatAmount, generateMasterKey, generateMnemonic, getAddressHrp, getAddressId, getAddressStorageKey, getCoinIdByName, getCoinIdBySymbol, getCurrentStateHash, getPublicKey, getSphere, getTokenDecimals, getTokenDefinition, getTokenIconUrl, getTokenId, getTokenName, getTokenSymbol, hasMissingNewStateHash, hasUncommittedTransactions, hasValidTxfData, hash160, hashSignMessage, hexToBytes, identityFromMnemonicSync, initSphere, isArchivedKey, isCombinedTransferBundleV6, isForkedKey, isInstantSplitBundle, isInstantSplitBundleV4, isInstantSplitBundleV5, isKnownToken, isPaymentSessionTerminal, isPaymentSessionTimedOut, isSQLiteDatabase, isSphereError, isTextWalletEncrypted, isTokenKey, isValidBech32, isValidNametag, isValidPrivateKey, isValidTokenId, isWalletDatEncrypted, isWalletTextFormat, keyFromTokenId, loadSphere, logger, mnemonicToSeedSync, normalizeSdkTokenToStorage, objectToTxf, parseAndDecryptWalletDat, parseAndDecryptWalletText, parseForkedKey, parseTxfStorageData, parseWalletDat, parseWalletText, randomBytes, randomHex, randomUUID, ripemd160, sha256, signMessage, sleep, sphereExists, toHumanReadable, toSmallestUnit, tokenIdFromArchivedKey, tokenIdFromKey, tokenToTxf, txfToToken, validateMnemonic, verifySignedMessage };
|
package/dist/index.js
CHANGED
|
@@ -1074,6 +1074,73 @@ function generateAddressInfo(privateKey, index, path, prefix = "alpha") {
|
|
|
1074
1074
|
index
|
|
1075
1075
|
};
|
|
1076
1076
|
}
|
|
1077
|
+
var SIGN_MESSAGE_PREFIX = "Sphere Signed Message:\n";
|
|
1078
|
+
function varint(n) {
|
|
1079
|
+
if (n < 253) return new Uint8Array([n]);
|
|
1080
|
+
const buf = new Uint8Array(3);
|
|
1081
|
+
buf[0] = 253;
|
|
1082
|
+
buf[1] = n & 255;
|
|
1083
|
+
buf[2] = n >> 8 & 255;
|
|
1084
|
+
return buf;
|
|
1085
|
+
}
|
|
1086
|
+
function hashSignMessage(message) {
|
|
1087
|
+
const prefix = new TextEncoder().encode(SIGN_MESSAGE_PREFIX);
|
|
1088
|
+
const msg = new TextEncoder().encode(message);
|
|
1089
|
+
const prefixLen = varint(prefix.length);
|
|
1090
|
+
const msgLen = varint(msg.length);
|
|
1091
|
+
const full = new Uint8Array(prefixLen.length + prefix.length + msgLen.length + msg.length);
|
|
1092
|
+
let off = 0;
|
|
1093
|
+
full.set(prefixLen, off);
|
|
1094
|
+
off += prefixLen.length;
|
|
1095
|
+
full.set(prefix, off);
|
|
1096
|
+
off += prefix.length;
|
|
1097
|
+
full.set(msgLen, off);
|
|
1098
|
+
off += msgLen.length;
|
|
1099
|
+
full.set(msg, off);
|
|
1100
|
+
const hex = Array.from(full).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1101
|
+
const h1 = CryptoJS2.SHA256(CryptoJS2.enc.Hex.parse(hex)).toString();
|
|
1102
|
+
return CryptoJS2.SHA256(CryptoJS2.enc.Hex.parse(h1)).toString();
|
|
1103
|
+
}
|
|
1104
|
+
function signMessage(privateKeyHex, message) {
|
|
1105
|
+
const keyPair = ec.keyFromPrivate(privateKeyHex, "hex");
|
|
1106
|
+
const hashHex = hashSignMessage(message);
|
|
1107
|
+
const hashBytes = Buffer.from(hashHex, "hex");
|
|
1108
|
+
const sig = keyPair.sign(hashBytes, { canonical: true });
|
|
1109
|
+
const pub = keyPair.getPublic();
|
|
1110
|
+
let recoveryParam = -1;
|
|
1111
|
+
for (let i = 0; i < 4; i++) {
|
|
1112
|
+
try {
|
|
1113
|
+
if (ec.recoverPubKey(hashBytes, sig, i).eq(pub)) {
|
|
1114
|
+
recoveryParam = i;
|
|
1115
|
+
break;
|
|
1116
|
+
}
|
|
1117
|
+
} catch {
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
if (recoveryParam === -1) {
|
|
1121
|
+
throw new SphereError("Could not find recovery parameter", "SIGNING_ERROR");
|
|
1122
|
+
}
|
|
1123
|
+
const v = (31 + recoveryParam).toString(16).padStart(2, "0");
|
|
1124
|
+
const r = sig.r.toString("hex").padStart(64, "0");
|
|
1125
|
+
const s = sig.s.toString("hex").padStart(64, "0");
|
|
1126
|
+
return v + r + s;
|
|
1127
|
+
}
|
|
1128
|
+
function verifySignedMessage(message, signature, expectedPubkey) {
|
|
1129
|
+
if (signature.length !== 130) return false;
|
|
1130
|
+
const v = parseInt(signature.slice(0, 2), 16) - 31;
|
|
1131
|
+
const r = signature.slice(2, 66);
|
|
1132
|
+
const s = signature.slice(66, 130);
|
|
1133
|
+
if (v < 0 || v > 3) return false;
|
|
1134
|
+
const hashHex = hashSignMessage(message);
|
|
1135
|
+
const hashBytes = Buffer.from(hashHex, "hex");
|
|
1136
|
+
try {
|
|
1137
|
+
const recovered = ec.recoverPubKey(hashBytes, { r, s }, v);
|
|
1138
|
+
const recoveredHex = recovered.encode("hex", true);
|
|
1139
|
+
return recoveredHex === expectedPubkey;
|
|
1140
|
+
} catch {
|
|
1141
|
+
return false;
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1077
1144
|
|
|
1078
1145
|
// l1/crypto.ts
|
|
1079
1146
|
import CryptoJS3 from "crypto-js";
|
|
@@ -14294,6 +14361,23 @@ var Sphere = class _Sphere {
|
|
|
14294
14361
|
return this._initialized;
|
|
14295
14362
|
}
|
|
14296
14363
|
// ===========================================================================
|
|
14364
|
+
// Public Methods - Signing
|
|
14365
|
+
// ===========================================================================
|
|
14366
|
+
/**
|
|
14367
|
+
* Sign a plaintext message with the wallet's secp256k1 private key.
|
|
14368
|
+
*
|
|
14369
|
+
* Returns a 130-character hex string: v (2) + r (64) + s (64).
|
|
14370
|
+
* The private key never leaves the SDK boundary.
|
|
14371
|
+
*
|
|
14372
|
+
* @throws SphereError if the wallet is not initialized or identity is missing
|
|
14373
|
+
*/
|
|
14374
|
+
signMessage(message) {
|
|
14375
|
+
if (!this._identity?.privateKey) {
|
|
14376
|
+
throw new SphereError("Wallet not initialized \u2014 cannot sign", "NOT_INITIALIZED");
|
|
14377
|
+
}
|
|
14378
|
+
return signMessage(this._identity.privateKey, message);
|
|
14379
|
+
}
|
|
14380
|
+
// ===========================================================================
|
|
14297
14381
|
// Public Methods - Providers Access
|
|
14298
14382
|
// ===========================================================================
|
|
14299
14383
|
getStorage() {
|
|
@@ -15679,6 +15763,17 @@ var Sphere = class _Sphere {
|
|
|
15679
15763
|
if (this._identity?.nametag) {
|
|
15680
15764
|
throw new SphereError(`Unicity ID already registered for address ${this._currentAddressIndex}: @${this._identity.nametag}`, "ALREADY_INITIALIZED");
|
|
15681
15765
|
}
|
|
15766
|
+
if (!this._payments.hasNametag()) {
|
|
15767
|
+
logger.debug("Sphere", `Minting nametag token for @${cleanNametag}...`);
|
|
15768
|
+
const result = await this.mintNametag(cleanNametag);
|
|
15769
|
+
if (!result.success) {
|
|
15770
|
+
throw new SphereError(
|
|
15771
|
+
`Failed to mint nametag token: ${result.error}`,
|
|
15772
|
+
"AGGREGATOR_ERROR"
|
|
15773
|
+
);
|
|
15774
|
+
}
|
|
15775
|
+
logger.debug("Sphere", `Nametag token minted successfully`);
|
|
15776
|
+
}
|
|
15682
15777
|
if (this._transport.publishIdentityBinding) {
|
|
15683
15778
|
const success = await this._transport.publishIdentityBinding(
|
|
15684
15779
|
this._identity.chainPubkey,
|
|
@@ -15702,15 +15797,6 @@ var Sphere = class _Sphere {
|
|
|
15702
15797
|
nametags.set(0, cleanNametag);
|
|
15703
15798
|
}
|
|
15704
15799
|
await this.persistAddressNametags();
|
|
15705
|
-
if (!this._payments.hasNametag()) {
|
|
15706
|
-
logger.debug("Sphere", `Minting nametag token for @${cleanNametag}...`);
|
|
15707
|
-
const result = await this.mintNametag(cleanNametag);
|
|
15708
|
-
if (!result.success) {
|
|
15709
|
-
logger.warn("Sphere", `Failed to mint nametag token: ${result.error}`);
|
|
15710
|
-
} else {
|
|
15711
|
-
logger.debug("Sphere", `Nametag token minted successfully`);
|
|
15712
|
-
}
|
|
15713
|
-
}
|
|
15714
15800
|
this.emitEvent("nametag:registered", {
|
|
15715
15801
|
nametag: cleanNametag,
|
|
15716
15802
|
addressIndex: this._currentAddressIndex
|
|
@@ -17046,8 +17132,12 @@ import {
|
|
|
17046
17132
|
normalizeNametag as normalizeNametag3,
|
|
17047
17133
|
isPhoneNumber as isPhoneNumber2,
|
|
17048
17134
|
hashNametag,
|
|
17049
|
-
|
|
17135
|
+
hashAddressForTag,
|
|
17136
|
+
areSameNametag,
|
|
17137
|
+
encryptNametag,
|
|
17138
|
+
decryptNametag
|
|
17050
17139
|
} from "@unicitylabs/nostr-js-sdk";
|
|
17140
|
+
import { NostrClient as NostrClient2, NostrKeyManager as NostrKeyManager2 } from "@unicitylabs/nostr-js-sdk";
|
|
17051
17141
|
|
|
17052
17142
|
// price/CoinGeckoPriceProvider.ts
|
|
17053
17143
|
init_logger();
|
|
@@ -17319,7 +17409,10 @@ export {
|
|
|
17319
17409
|
NETWORKS,
|
|
17320
17410
|
NIP29_KINDS,
|
|
17321
17411
|
NOSTR_EVENT_KINDS,
|
|
17412
|
+
NostrClient2 as NostrClient,
|
|
17413
|
+
NostrKeyManager2 as NostrKeyManager,
|
|
17322
17414
|
PaymentsModule,
|
|
17415
|
+
SIGN_MESSAGE_PREFIX,
|
|
17323
17416
|
STORAGE_KEYS,
|
|
17324
17417
|
STORAGE_KEYS_ADDRESS,
|
|
17325
17418
|
STORAGE_KEYS_GLOBAL,
|
|
@@ -17355,6 +17448,7 @@ export {
|
|
|
17355
17448
|
createTokenValidator,
|
|
17356
17449
|
decodeBech32,
|
|
17357
17450
|
decryptCMasterKey,
|
|
17451
|
+
decryptNametag,
|
|
17358
17452
|
decryptPrivateKey,
|
|
17359
17453
|
decryptTextFormatKey,
|
|
17360
17454
|
deriveAddressInfo,
|
|
@@ -17362,6 +17456,7 @@ export {
|
|
|
17362
17456
|
deriveKeyAtPath,
|
|
17363
17457
|
doubleSha256,
|
|
17364
17458
|
encodeBech32,
|
|
17459
|
+
encryptNametag,
|
|
17365
17460
|
extractFromText,
|
|
17366
17461
|
findPattern,
|
|
17367
17462
|
forkedKeyFromTokenIdAndState,
|
|
@@ -17386,7 +17481,9 @@ export {
|
|
|
17386
17481
|
hasUncommittedTransactions,
|
|
17387
17482
|
hasValidTxfData,
|
|
17388
17483
|
hash160,
|
|
17484
|
+
hashAddressForTag,
|
|
17389
17485
|
hashNametag,
|
|
17486
|
+
hashSignMessage,
|
|
17390
17487
|
hexToBytes,
|
|
17391
17488
|
identityFromMnemonicSync,
|
|
17392
17489
|
initSphere,
|
|
@@ -17428,6 +17525,7 @@ export {
|
|
|
17428
17525
|
randomUUID,
|
|
17429
17526
|
ripemd160,
|
|
17430
17527
|
sha256,
|
|
17528
|
+
signMessage,
|
|
17431
17529
|
sleep,
|
|
17432
17530
|
sphereExists,
|
|
17433
17531
|
toHumanReadable,
|
|
@@ -17436,7 +17534,8 @@ export {
|
|
|
17436
17534
|
tokenIdFromKey,
|
|
17437
17535
|
tokenToTxf,
|
|
17438
17536
|
txfToToken,
|
|
17439
|
-
validateMnemonic2 as validateMnemonic
|
|
17537
|
+
validateMnemonic2 as validateMnemonic,
|
|
17538
|
+
verifySignedMessage
|
|
17440
17539
|
};
|
|
17441
17540
|
/*! Bundled license information:
|
|
17442
17541
|
|