@unicitylabs/sphere-sdk 0.1.3 → 0.1.5
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/README.md +110 -15
- package/dist/core/index.cjs +829 -236
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +332 -210
- package/dist/core/index.d.ts +332 -210
- package/dist/core/index.js +829 -236
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +1224 -339
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +1221 -342
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/browser/ipfs.cjs +471 -37
- package/dist/impl/browser/ipfs.cjs.map +1 -1
- package/dist/impl/browser/ipfs.js +470 -36
- package/dist/impl/browser/ipfs.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +1238 -345
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.d.cts +142 -57
- package/dist/impl/nodejs/index.d.ts +142 -57
- package/dist/impl/nodejs/index.js +1245 -348
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +871 -235
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1395 -503
- package/dist/index.d.ts +1395 -503
- package/dist/index.js +862 -235
- package/dist/index.js.map +1 -1
- package/package.json +6 -1
package/dist/core/index.d.ts
CHANGED
|
@@ -290,11 +290,12 @@ interface BaseProvider extends ProviderMetadata {
|
|
|
290
290
|
getStatus(): ProviderStatus;
|
|
291
291
|
}
|
|
292
292
|
interface Identity {
|
|
293
|
-
|
|
293
|
+
/** 33-byte compressed secp256k1 public key (for L3 chain) */
|
|
294
|
+
readonly chainPubkey: string;
|
|
294
295
|
/** L1 address (alpha1...) */
|
|
295
|
-
readonly
|
|
296
|
-
/** L3
|
|
297
|
-
readonly
|
|
296
|
+
readonly l1Address: string;
|
|
297
|
+
/** L3 DIRECT address (DIRECT://...) */
|
|
298
|
+
readonly directAddress?: string;
|
|
298
299
|
readonly ipnsName?: string;
|
|
299
300
|
readonly nametag?: string;
|
|
300
301
|
}
|
|
@@ -307,6 +308,8 @@ interface Token {
|
|
|
307
308
|
readonly coinId: string;
|
|
308
309
|
readonly symbol: string;
|
|
309
310
|
readonly name: string;
|
|
311
|
+
readonly decimals: number;
|
|
312
|
+
readonly iconUrl?: string;
|
|
310
313
|
readonly amount: string;
|
|
311
314
|
status: TokenStatus;
|
|
312
315
|
readonly createdAt: number;
|
|
@@ -479,7 +482,7 @@ interface BroadcastMessage {
|
|
|
479
482
|
readonly timestamp: number;
|
|
480
483
|
readonly tags?: string[];
|
|
481
484
|
}
|
|
482
|
-
type SphereEventType = 'transfer:incoming' | 'transfer:confirmed' | 'transfer:failed' | 'payment_request:incoming' | 'payment_request:accepted' | 'payment_request:rejected' | 'payment_request:paid' | 'payment_request:response' | 'message:dm' | 'message:broadcast' | 'sync:started' | 'sync:completed' | 'sync:provider' | 'sync:error' | 'connection:changed' | 'nametag:registered' | 'identity:changed';
|
|
485
|
+
type SphereEventType = 'transfer:incoming' | 'transfer:confirmed' | 'transfer:failed' | 'payment_request:incoming' | 'payment_request:accepted' | 'payment_request:rejected' | 'payment_request:paid' | 'payment_request:response' | 'message:dm' | 'message:broadcast' | 'sync:started' | 'sync:completed' | 'sync:provider' | 'sync:error' | 'connection:changed' | 'nametag:registered' | 'nametag:recovered' | 'identity:changed';
|
|
483
486
|
interface SphereEventMap {
|
|
484
487
|
'transfer:incoming': IncomingTransfer;
|
|
485
488
|
'transfer:confirmed': TransferResult;
|
|
@@ -517,10 +520,13 @@ interface SphereEventMap {
|
|
|
517
520
|
nametag: string;
|
|
518
521
|
addressIndex: number;
|
|
519
522
|
};
|
|
523
|
+
'nametag:recovered': {
|
|
524
|
+
nametag: string;
|
|
525
|
+
};
|
|
520
526
|
'identity:changed': {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
527
|
+
l1Address: string;
|
|
528
|
+
directAddress?: string;
|
|
529
|
+
chainPubkey: string;
|
|
524
530
|
nametag?: string;
|
|
525
531
|
addressIndex: number;
|
|
526
532
|
};
|
|
@@ -584,6 +590,245 @@ interface WalletJSONExportOptions {
|
|
|
584
590
|
addressCount?: number;
|
|
585
591
|
}
|
|
586
592
|
|
|
593
|
+
/**
|
|
594
|
+
* Transport Provider Interface
|
|
595
|
+
* Platform-independent P2P messaging abstraction
|
|
596
|
+
*/
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* P2P messaging transport provider
|
|
600
|
+
*/
|
|
601
|
+
interface TransportProvider extends BaseProvider {
|
|
602
|
+
/**
|
|
603
|
+
* Set identity for signing/encryption
|
|
604
|
+
*/
|
|
605
|
+
setIdentity(identity: FullIdentity): void;
|
|
606
|
+
/**
|
|
607
|
+
* Send encrypted direct message
|
|
608
|
+
* @param recipientTransportPubkey - Transport-specific pubkey for messaging
|
|
609
|
+
* @returns Event ID
|
|
610
|
+
*/
|
|
611
|
+
sendMessage(recipientTransportPubkey: string, content: string): Promise<string>;
|
|
612
|
+
/**
|
|
613
|
+
* Subscribe to incoming direct messages
|
|
614
|
+
* @returns Unsubscribe function
|
|
615
|
+
*/
|
|
616
|
+
onMessage(handler: MessageHandler): () => void;
|
|
617
|
+
/**
|
|
618
|
+
* Send token transfer payload
|
|
619
|
+
* @param recipientTransportPubkey - Transport-specific pubkey for messaging
|
|
620
|
+
* @returns Event ID
|
|
621
|
+
*/
|
|
622
|
+
sendTokenTransfer(recipientTransportPubkey: string, payload: TokenTransferPayload): Promise<string>;
|
|
623
|
+
/**
|
|
624
|
+
* Subscribe to incoming token transfers
|
|
625
|
+
* @returns Unsubscribe function
|
|
626
|
+
*/
|
|
627
|
+
onTokenTransfer(handler: TokenTransferHandler): () => void;
|
|
628
|
+
/**
|
|
629
|
+
* Resolve nametag to public key
|
|
630
|
+
*/
|
|
631
|
+
resolveNametag?(nametag: string): Promise<string | null>;
|
|
632
|
+
/**
|
|
633
|
+
* Resolve nametag to full address information
|
|
634
|
+
* Returns transportPubkey, chainPubkey, l1Address, directAddress, proxyAddress
|
|
635
|
+
*/
|
|
636
|
+
resolveNametagInfo?(nametag: string): Promise<NametagInfo | null>;
|
|
637
|
+
/**
|
|
638
|
+
* Recover nametag for current identity by decrypting stored encrypted nametag
|
|
639
|
+
* Used after wallet import to recover associated nametag
|
|
640
|
+
* @returns Decrypted nametag or null if none found
|
|
641
|
+
*/
|
|
642
|
+
recoverNametag?(): Promise<string | null>;
|
|
643
|
+
/**
|
|
644
|
+
* Register a nametag for this identity
|
|
645
|
+
* @param nametag - Nametag to register
|
|
646
|
+
* @param chainPubkey - 33-byte compressed secp256k1 public key (for L1/L3)
|
|
647
|
+
* @param directAddress - L3 DIRECT address (DIRECT://...)
|
|
648
|
+
* @returns true if successful, false if already taken
|
|
649
|
+
*/
|
|
650
|
+
registerNametag?(nametag: string, chainPubkey: string, directAddress: string): Promise<boolean>;
|
|
651
|
+
/**
|
|
652
|
+
* Publish nametag binding
|
|
653
|
+
*/
|
|
654
|
+
publishNametag?(nametag: string, address: string): Promise<void>;
|
|
655
|
+
/**
|
|
656
|
+
* Subscribe to broadcast messages (global/channel)
|
|
657
|
+
*/
|
|
658
|
+
subscribeToBroadcast?(tags: string[], handler: BroadcastHandler): () => void;
|
|
659
|
+
/**
|
|
660
|
+
* Publish broadcast message
|
|
661
|
+
*/
|
|
662
|
+
publishBroadcast?(content: string, tags?: string[]): Promise<string>;
|
|
663
|
+
/**
|
|
664
|
+
* Send payment request to a recipient
|
|
665
|
+
* @param recipientTransportPubkey - Transport-specific pubkey for messaging
|
|
666
|
+
* @returns Event ID
|
|
667
|
+
*/
|
|
668
|
+
sendPaymentRequest?(recipientTransportPubkey: string, request: PaymentRequestPayload): Promise<string>;
|
|
669
|
+
/**
|
|
670
|
+
* Subscribe to incoming payment requests
|
|
671
|
+
* @returns Unsubscribe function
|
|
672
|
+
*/
|
|
673
|
+
onPaymentRequest?(handler: PaymentRequestHandler): () => void;
|
|
674
|
+
/**
|
|
675
|
+
* Send response to a payment request
|
|
676
|
+
* @param recipientTransportPubkey - Transport-specific pubkey for messaging
|
|
677
|
+
* @returns Event ID
|
|
678
|
+
*/
|
|
679
|
+
sendPaymentRequestResponse?(recipientTransportPubkey: string, response: PaymentRequestResponsePayload): Promise<string>;
|
|
680
|
+
/**
|
|
681
|
+
* Subscribe to incoming payment request responses
|
|
682
|
+
* @returns Unsubscribe function
|
|
683
|
+
*/
|
|
684
|
+
onPaymentRequestResponse?(handler: PaymentRequestResponseHandler): () => void;
|
|
685
|
+
/**
|
|
686
|
+
* Get list of configured relay URLs
|
|
687
|
+
*/
|
|
688
|
+
getRelays?(): string[];
|
|
689
|
+
/**
|
|
690
|
+
* Get list of currently connected relay URLs
|
|
691
|
+
*/
|
|
692
|
+
getConnectedRelays?(): string[];
|
|
693
|
+
/**
|
|
694
|
+
* Add a relay dynamically
|
|
695
|
+
* @returns true if added successfully
|
|
696
|
+
*/
|
|
697
|
+
addRelay?(relayUrl: string): Promise<boolean>;
|
|
698
|
+
/**
|
|
699
|
+
* Remove a relay dynamically
|
|
700
|
+
* @returns true if removed successfully
|
|
701
|
+
*/
|
|
702
|
+
removeRelay?(relayUrl: string): Promise<boolean>;
|
|
703
|
+
/**
|
|
704
|
+
* Check if a relay is configured
|
|
705
|
+
*/
|
|
706
|
+
hasRelay?(relayUrl: string): boolean;
|
|
707
|
+
/**
|
|
708
|
+
* Check if a relay is currently connected
|
|
709
|
+
*/
|
|
710
|
+
isRelayConnected?(relayUrl: string): boolean;
|
|
711
|
+
}
|
|
712
|
+
interface IncomingMessage {
|
|
713
|
+
id: string;
|
|
714
|
+
/** Transport-specific pubkey of sender */
|
|
715
|
+
senderTransportPubkey: string;
|
|
716
|
+
/** Sender's nametag (if known from NIP-17 unwrap) */
|
|
717
|
+
senderNametag?: string;
|
|
718
|
+
content: string;
|
|
719
|
+
timestamp: number;
|
|
720
|
+
encrypted: boolean;
|
|
721
|
+
}
|
|
722
|
+
type MessageHandler = (message: IncomingMessage) => void;
|
|
723
|
+
interface TokenTransferPayload {
|
|
724
|
+
/** Serialized token data */
|
|
725
|
+
token: string;
|
|
726
|
+
/** Inclusion proof */
|
|
727
|
+
proof: unknown;
|
|
728
|
+
/** Optional memo */
|
|
729
|
+
memo?: string;
|
|
730
|
+
/** Sender info */
|
|
731
|
+
sender?: {
|
|
732
|
+
/** Transport-specific pubkey */
|
|
733
|
+
transportPubkey: string;
|
|
734
|
+
nametag?: string;
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
interface IncomingTokenTransfer {
|
|
738
|
+
id: string;
|
|
739
|
+
/** Transport-specific pubkey of sender */
|
|
740
|
+
senderTransportPubkey: string;
|
|
741
|
+
payload: TokenTransferPayload;
|
|
742
|
+
timestamp: number;
|
|
743
|
+
}
|
|
744
|
+
type TokenTransferHandler = (transfer: IncomingTokenTransfer) => void;
|
|
745
|
+
interface PaymentRequestPayload {
|
|
746
|
+
/** Amount requested (in smallest units) */
|
|
747
|
+
amount: string | bigint;
|
|
748
|
+
/** Coin/token type ID */
|
|
749
|
+
coinId: string;
|
|
750
|
+
/** Message/memo for recipient */
|
|
751
|
+
message?: string;
|
|
752
|
+
/** Recipient's nametag (who should pay) */
|
|
753
|
+
recipientNametag?: string;
|
|
754
|
+
/** Custom metadata */
|
|
755
|
+
metadata?: Record<string, unknown>;
|
|
756
|
+
}
|
|
757
|
+
interface IncomingPaymentRequest {
|
|
758
|
+
/** Event ID */
|
|
759
|
+
id: string;
|
|
760
|
+
/** Transport-specific pubkey of sender */
|
|
761
|
+
senderTransportPubkey: string;
|
|
762
|
+
/** Parsed request data */
|
|
763
|
+
request: {
|
|
764
|
+
requestId: string;
|
|
765
|
+
amount: string;
|
|
766
|
+
coinId: string;
|
|
767
|
+
message?: string;
|
|
768
|
+
recipientNametag?: string;
|
|
769
|
+
metadata?: Record<string, unknown>;
|
|
770
|
+
};
|
|
771
|
+
/** Timestamp */
|
|
772
|
+
timestamp: number;
|
|
773
|
+
}
|
|
774
|
+
type PaymentRequestHandler = (request: IncomingPaymentRequest) => void;
|
|
775
|
+
type PaymentRequestResponseType = 'accepted' | 'rejected' | 'paid';
|
|
776
|
+
interface PaymentRequestResponsePayload {
|
|
777
|
+
/** Original request ID */
|
|
778
|
+
requestId: string;
|
|
779
|
+
/** Response type */
|
|
780
|
+
responseType: PaymentRequestResponseType;
|
|
781
|
+
/** Optional message */
|
|
782
|
+
message?: string;
|
|
783
|
+
/** Transfer ID (if paid) */
|
|
784
|
+
transferId?: string;
|
|
785
|
+
}
|
|
786
|
+
interface IncomingPaymentRequestResponse {
|
|
787
|
+
/** Event ID */
|
|
788
|
+
id: string;
|
|
789
|
+
/** Transport-specific pubkey of responder */
|
|
790
|
+
responderTransportPubkey: string;
|
|
791
|
+
/** Parsed response data */
|
|
792
|
+
response: {
|
|
793
|
+
requestId: string;
|
|
794
|
+
responseType: PaymentRequestResponseType;
|
|
795
|
+
message?: string;
|
|
796
|
+
transferId?: string;
|
|
797
|
+
};
|
|
798
|
+
/** Timestamp */
|
|
799
|
+
timestamp: number;
|
|
800
|
+
}
|
|
801
|
+
type PaymentRequestResponseHandler = (response: IncomingPaymentRequestResponse) => void;
|
|
802
|
+
interface IncomingBroadcast {
|
|
803
|
+
id: string;
|
|
804
|
+
/** Transport-specific pubkey of author */
|
|
805
|
+
authorTransportPubkey: string;
|
|
806
|
+
content: string;
|
|
807
|
+
tags: string[];
|
|
808
|
+
timestamp: number;
|
|
809
|
+
}
|
|
810
|
+
type BroadcastHandler = (broadcast: IncomingBroadcast) => void;
|
|
811
|
+
/**
|
|
812
|
+
* Full nametag address information
|
|
813
|
+
* Used for resolving nametag to all address formats
|
|
814
|
+
*/
|
|
815
|
+
interface NametagInfo {
|
|
816
|
+
/** Nametag name (without @) */
|
|
817
|
+
nametag: string;
|
|
818
|
+
/** Transport-specific pubkey (for messaging/encryption) */
|
|
819
|
+
transportPubkey: string;
|
|
820
|
+
/** 33-byte compressed secp256k1 public key (for L3 chain) */
|
|
821
|
+
chainPubkey: string;
|
|
822
|
+
/** L1 address (alpha1...) */
|
|
823
|
+
l1Address: string;
|
|
824
|
+
/** L3 DIRECT address (DIRECT://...) */
|
|
825
|
+
directAddress: string;
|
|
826
|
+
/** L3 PROXY address derived from nametag hash (PROXY:...) */
|
|
827
|
+
proxyAddress: string;
|
|
828
|
+
/** Event timestamp */
|
|
829
|
+
timestamp: number;
|
|
830
|
+
}
|
|
831
|
+
|
|
587
832
|
/**
|
|
588
833
|
* L1 Payments Sub-Module
|
|
589
834
|
*
|
|
@@ -653,6 +898,8 @@ interface L1PaymentsModuleDependencies {
|
|
|
653
898
|
identity: FullIdentity;
|
|
654
899
|
chainCode?: string;
|
|
655
900
|
addresses?: string[];
|
|
901
|
+
/** Transport provider for nametag resolution (optional) */
|
|
902
|
+
transport?: TransportProvider;
|
|
656
903
|
}
|
|
657
904
|
/**
|
|
658
905
|
* L1 Payments Module - Full Implementation
|
|
@@ -667,9 +914,23 @@ declare class L1PaymentsModule {
|
|
|
667
914
|
private _chainCode?;
|
|
668
915
|
private _addresses;
|
|
669
916
|
private _wallet?;
|
|
917
|
+
private _transport?;
|
|
670
918
|
constructor(config?: L1PaymentsModuleConfig);
|
|
671
919
|
initialize(deps: L1PaymentsModuleDependencies): Promise<void>;
|
|
672
920
|
destroy(): void;
|
|
921
|
+
/**
|
|
922
|
+
* Check if a string looks like an L1 address (alpha1... or alphat1...)
|
|
923
|
+
*/
|
|
924
|
+
private isL1Address;
|
|
925
|
+
/**
|
|
926
|
+
* Resolve recipient to L1 address
|
|
927
|
+
* Supports: L1 address (alpha1...), nametag (with or without @)
|
|
928
|
+
*/
|
|
929
|
+
private resolveL1Address;
|
|
930
|
+
/**
|
|
931
|
+
* Resolve nametag to L1 address using transport provider
|
|
932
|
+
*/
|
|
933
|
+
private resolveNametagToL1Address;
|
|
673
934
|
send(request: L1SendRequest): Promise<L1SendResult>;
|
|
674
935
|
getBalance(): Promise<L1Balance>;
|
|
675
936
|
getUtxos(): Promise<L1Utxo[]>;
|
|
@@ -878,201 +1139,6 @@ interface TxfInvalidEntry {
|
|
|
878
1139
|
detectedAt: number;
|
|
879
1140
|
}
|
|
880
1141
|
|
|
881
|
-
/**
|
|
882
|
-
* Transport Provider Interface
|
|
883
|
-
* Platform-independent P2P messaging abstraction
|
|
884
|
-
*/
|
|
885
|
-
|
|
886
|
-
/**
|
|
887
|
-
* P2P messaging transport provider
|
|
888
|
-
*/
|
|
889
|
-
interface TransportProvider extends BaseProvider {
|
|
890
|
-
/**
|
|
891
|
-
* Set identity for signing/encryption
|
|
892
|
-
*/
|
|
893
|
-
setIdentity(identity: FullIdentity): void;
|
|
894
|
-
/**
|
|
895
|
-
* Send encrypted direct message
|
|
896
|
-
* @returns Event ID
|
|
897
|
-
*/
|
|
898
|
-
sendMessage(recipientPubkey: string, content: string): Promise<string>;
|
|
899
|
-
/**
|
|
900
|
-
* Subscribe to incoming direct messages
|
|
901
|
-
* @returns Unsubscribe function
|
|
902
|
-
*/
|
|
903
|
-
onMessage(handler: MessageHandler): () => void;
|
|
904
|
-
/**
|
|
905
|
-
* Send token transfer payload
|
|
906
|
-
* @returns Event ID
|
|
907
|
-
*/
|
|
908
|
-
sendTokenTransfer(recipientPubkey: string, payload: TokenTransferPayload): Promise<string>;
|
|
909
|
-
/**
|
|
910
|
-
* Subscribe to incoming token transfers
|
|
911
|
-
* @returns Unsubscribe function
|
|
912
|
-
*/
|
|
913
|
-
onTokenTransfer(handler: TokenTransferHandler): () => void;
|
|
914
|
-
/**
|
|
915
|
-
* Resolve nametag to public key
|
|
916
|
-
*/
|
|
917
|
-
resolveNametag?(nametag: string): Promise<string | null>;
|
|
918
|
-
/**
|
|
919
|
-
* Register a nametag for this identity
|
|
920
|
-
* @returns true if successful, false if already taken
|
|
921
|
-
*/
|
|
922
|
-
registerNametag?(nametag: string, publicKey: string): Promise<boolean>;
|
|
923
|
-
/**
|
|
924
|
-
* Publish nametag binding
|
|
925
|
-
*/
|
|
926
|
-
publishNametag?(nametag: string, address: string): Promise<void>;
|
|
927
|
-
/**
|
|
928
|
-
* Subscribe to broadcast messages (global/channel)
|
|
929
|
-
*/
|
|
930
|
-
subscribeToBroadcast?(tags: string[], handler: BroadcastHandler): () => void;
|
|
931
|
-
/**
|
|
932
|
-
* Publish broadcast message
|
|
933
|
-
*/
|
|
934
|
-
publishBroadcast?(content: string, tags?: string[]): Promise<string>;
|
|
935
|
-
/**
|
|
936
|
-
* Send payment request to a recipient
|
|
937
|
-
* @returns Event ID
|
|
938
|
-
*/
|
|
939
|
-
sendPaymentRequest?(recipientPubkey: string, request: PaymentRequestPayload): Promise<string>;
|
|
940
|
-
/**
|
|
941
|
-
* Subscribe to incoming payment requests
|
|
942
|
-
* @returns Unsubscribe function
|
|
943
|
-
*/
|
|
944
|
-
onPaymentRequest?(handler: PaymentRequestHandler): () => void;
|
|
945
|
-
/**
|
|
946
|
-
* Send response to a payment request
|
|
947
|
-
* @returns Event ID
|
|
948
|
-
*/
|
|
949
|
-
sendPaymentRequestResponse?(recipientPubkey: string, response: PaymentRequestResponsePayload): Promise<string>;
|
|
950
|
-
/**
|
|
951
|
-
* Subscribe to incoming payment request responses
|
|
952
|
-
* @returns Unsubscribe function
|
|
953
|
-
*/
|
|
954
|
-
onPaymentRequestResponse?(handler: PaymentRequestResponseHandler): () => void;
|
|
955
|
-
/**
|
|
956
|
-
* Get list of configured relay URLs
|
|
957
|
-
*/
|
|
958
|
-
getRelays?(): string[];
|
|
959
|
-
/**
|
|
960
|
-
* Get list of currently connected relay URLs
|
|
961
|
-
*/
|
|
962
|
-
getConnectedRelays?(): string[];
|
|
963
|
-
/**
|
|
964
|
-
* Add a relay dynamically
|
|
965
|
-
* @returns true if added successfully
|
|
966
|
-
*/
|
|
967
|
-
addRelay?(relayUrl: string): Promise<boolean>;
|
|
968
|
-
/**
|
|
969
|
-
* Remove a relay dynamically
|
|
970
|
-
* @returns true if removed successfully
|
|
971
|
-
*/
|
|
972
|
-
removeRelay?(relayUrl: string): Promise<boolean>;
|
|
973
|
-
/**
|
|
974
|
-
* Check if a relay is configured
|
|
975
|
-
*/
|
|
976
|
-
hasRelay?(relayUrl: string): boolean;
|
|
977
|
-
/**
|
|
978
|
-
* Check if a relay is currently connected
|
|
979
|
-
*/
|
|
980
|
-
isRelayConnected?(relayUrl: string): boolean;
|
|
981
|
-
}
|
|
982
|
-
interface IncomingMessage {
|
|
983
|
-
id: string;
|
|
984
|
-
senderPubkey: string;
|
|
985
|
-
content: string;
|
|
986
|
-
timestamp: number;
|
|
987
|
-
encrypted: boolean;
|
|
988
|
-
}
|
|
989
|
-
type MessageHandler = (message: IncomingMessage) => void;
|
|
990
|
-
interface TokenTransferPayload {
|
|
991
|
-
/** Serialized token data */
|
|
992
|
-
token: string;
|
|
993
|
-
/** Inclusion proof */
|
|
994
|
-
proof: unknown;
|
|
995
|
-
/** Optional memo */
|
|
996
|
-
memo?: string;
|
|
997
|
-
/** Sender info */
|
|
998
|
-
sender?: {
|
|
999
|
-
pubkey: string;
|
|
1000
|
-
nametag?: string;
|
|
1001
|
-
};
|
|
1002
|
-
}
|
|
1003
|
-
interface IncomingTokenTransfer {
|
|
1004
|
-
id: string;
|
|
1005
|
-
senderPubkey: string;
|
|
1006
|
-
payload: TokenTransferPayload;
|
|
1007
|
-
timestamp: number;
|
|
1008
|
-
}
|
|
1009
|
-
type TokenTransferHandler = (transfer: IncomingTokenTransfer) => void;
|
|
1010
|
-
interface PaymentRequestPayload {
|
|
1011
|
-
/** Amount requested (in smallest units) */
|
|
1012
|
-
amount: string | bigint;
|
|
1013
|
-
/** Coin/token type ID */
|
|
1014
|
-
coinId: string;
|
|
1015
|
-
/** Message/memo for recipient */
|
|
1016
|
-
message?: string;
|
|
1017
|
-
/** Recipient's nametag (who should pay) */
|
|
1018
|
-
recipientNametag?: string;
|
|
1019
|
-
/** Custom metadata */
|
|
1020
|
-
metadata?: Record<string, unknown>;
|
|
1021
|
-
}
|
|
1022
|
-
interface IncomingPaymentRequest {
|
|
1023
|
-
/** Event ID */
|
|
1024
|
-
id: string;
|
|
1025
|
-
/** Sender's public key */
|
|
1026
|
-
senderPubkey: string;
|
|
1027
|
-
/** Parsed request data */
|
|
1028
|
-
request: {
|
|
1029
|
-
requestId: string;
|
|
1030
|
-
amount: string;
|
|
1031
|
-
coinId: string;
|
|
1032
|
-
message?: string;
|
|
1033
|
-
recipientNametag?: string;
|
|
1034
|
-
metadata?: Record<string, unknown>;
|
|
1035
|
-
};
|
|
1036
|
-
/** Timestamp */
|
|
1037
|
-
timestamp: number;
|
|
1038
|
-
}
|
|
1039
|
-
type PaymentRequestHandler = (request: IncomingPaymentRequest) => void;
|
|
1040
|
-
type PaymentRequestResponseType = 'accepted' | 'rejected' | 'paid';
|
|
1041
|
-
interface PaymentRequestResponsePayload {
|
|
1042
|
-
/** Original request ID */
|
|
1043
|
-
requestId: string;
|
|
1044
|
-
/** Response type */
|
|
1045
|
-
responseType: PaymentRequestResponseType;
|
|
1046
|
-
/** Optional message */
|
|
1047
|
-
message?: string;
|
|
1048
|
-
/** Transfer ID (if paid) */
|
|
1049
|
-
transferId?: string;
|
|
1050
|
-
}
|
|
1051
|
-
interface IncomingPaymentRequestResponse {
|
|
1052
|
-
/** Event ID */
|
|
1053
|
-
id: string;
|
|
1054
|
-
/** Responder's public key */
|
|
1055
|
-
responderPubkey: string;
|
|
1056
|
-
/** Parsed response data */
|
|
1057
|
-
response: {
|
|
1058
|
-
requestId: string;
|
|
1059
|
-
responseType: PaymentRequestResponseType;
|
|
1060
|
-
message?: string;
|
|
1061
|
-
transferId?: string;
|
|
1062
|
-
};
|
|
1063
|
-
/** Timestamp */
|
|
1064
|
-
timestamp: number;
|
|
1065
|
-
}
|
|
1066
|
-
type PaymentRequestResponseHandler = (response: IncomingPaymentRequestResponse) => void;
|
|
1067
|
-
interface IncomingBroadcast {
|
|
1068
|
-
id: string;
|
|
1069
|
-
authorPubkey: string;
|
|
1070
|
-
content: string;
|
|
1071
|
-
tags: string[];
|
|
1072
|
-
timestamp: number;
|
|
1073
|
-
}
|
|
1074
|
-
type BroadcastHandler = (broadcast: IncomingBroadcast) => void;
|
|
1075
|
-
|
|
1076
1142
|
/**
|
|
1077
1143
|
* Oracle Provider Interface
|
|
1078
1144
|
* Platform-independent Unicity oracle abstraction
|
|
@@ -1302,6 +1368,14 @@ declare class PaymentsModule {
|
|
|
1302
1368
|
* Get coin name from coinId
|
|
1303
1369
|
*/
|
|
1304
1370
|
private getCoinName;
|
|
1371
|
+
/**
|
|
1372
|
+
* Get coin decimals from coinId
|
|
1373
|
+
*/
|
|
1374
|
+
private getCoinDecimals;
|
|
1375
|
+
/**
|
|
1376
|
+
* Get coin icon URL from coinId
|
|
1377
|
+
*/
|
|
1378
|
+
private getCoinIconUrl;
|
|
1305
1379
|
/**
|
|
1306
1380
|
* Send a payment request to someone
|
|
1307
1381
|
* @param recipientPubkeyOrNametag - Recipient's pubkey or @nametag
|
|
@@ -1554,6 +1628,15 @@ declare class PaymentsModule {
|
|
|
1554
1628
|
* Get pending transfers
|
|
1555
1629
|
*/
|
|
1556
1630
|
getPendingTransfers(): TransferResult[];
|
|
1631
|
+
/**
|
|
1632
|
+
* Detect if a string is an L3 address (not a nametag)
|
|
1633
|
+
* Returns true for: hex pubkeys (64+ chars), PROXY:, DIRECT: prefixed addresses
|
|
1634
|
+
*/
|
|
1635
|
+
private isL3Address;
|
|
1636
|
+
/**
|
|
1637
|
+
* Resolve recipient to Nostr pubkey for messaging
|
|
1638
|
+
* Supports: nametag (with or without @), hex pubkey
|
|
1639
|
+
*/
|
|
1557
1640
|
private resolveRecipient;
|
|
1558
1641
|
/**
|
|
1559
1642
|
* Create SDK TransferCommitment for a token transfer
|
|
@@ -1564,7 +1647,17 @@ declare class PaymentsModule {
|
|
|
1564
1647
|
*/
|
|
1565
1648
|
private createSigningService;
|
|
1566
1649
|
/**
|
|
1567
|
-
*
|
|
1650
|
+
* Create DirectAddress from a public key using UnmaskedPredicateReference
|
|
1651
|
+
*/
|
|
1652
|
+
private createDirectAddressFromPubkey;
|
|
1653
|
+
/**
|
|
1654
|
+
* Resolve nametag to 33-byte compressed public key using resolveNametagInfo
|
|
1655
|
+
* Returns null if nametag not found or publicKey not available
|
|
1656
|
+
*/
|
|
1657
|
+
private resolveNametagToPublicKey;
|
|
1658
|
+
/**
|
|
1659
|
+
* Resolve recipient to IAddress for L3 transfers
|
|
1660
|
+
* Supports: nametag (with or without @), PROXY:, DIRECT:, hex pubkey
|
|
1568
1661
|
*/
|
|
1569
1662
|
private resolveRecipientAddress;
|
|
1570
1663
|
private handleIncomingTransfer;
|
|
@@ -1829,6 +1922,7 @@ declare class Sphere {
|
|
|
1829
1922
|
private _derivationMode;
|
|
1830
1923
|
private _basePath;
|
|
1831
1924
|
private _currentAddressIndex;
|
|
1925
|
+
/** Map of addressId -> (nametagIndex -> nametag). Supports multiple nametags per address (e.g., from Nostr recovery) */
|
|
1832
1926
|
private _addressNametags;
|
|
1833
1927
|
private _storage;
|
|
1834
1928
|
private _tokenStorageProviders;
|
|
@@ -1882,6 +1976,7 @@ declare class Sphere {
|
|
|
1882
1976
|
static import(options: SphereImportOptions): Promise<Sphere>;
|
|
1883
1977
|
/**
|
|
1884
1978
|
* Clear wallet data from storage
|
|
1979
|
+
* Note: Token data is cleared via TokenStorageProvider, not here
|
|
1885
1980
|
*/
|
|
1886
1981
|
static clear(storage: StorageProvider): Promise<void>;
|
|
1887
1982
|
/**
|
|
@@ -2100,18 +2195,29 @@ declare class Sphere {
|
|
|
2100
2195
|
*/
|
|
2101
2196
|
getCurrentAddressIndex(): number;
|
|
2102
2197
|
/**
|
|
2103
|
-
* Get nametag for a specific address
|
|
2198
|
+
* Get primary nametag for a specific address
|
|
2199
|
+
*
|
|
2200
|
+
* @param addressId - Address identifier (DIRECT://xxx), defaults to current address
|
|
2201
|
+
* @returns Primary nametag (index 0) or undefined if not registered
|
|
2202
|
+
*/
|
|
2203
|
+
getNametagForAddress(addressId?: string): string | undefined;
|
|
2204
|
+
/**
|
|
2205
|
+
* Get all nametags for a specific address
|
|
2104
2206
|
*
|
|
2105
|
-
* @param
|
|
2106
|
-
* @returns
|
|
2207
|
+
* @param addressId - Address identifier (DIRECT://xxx), defaults to current address
|
|
2208
|
+
* @returns Map of nametagIndex to nametag, or undefined if no nametags
|
|
2107
2209
|
*/
|
|
2108
|
-
|
|
2210
|
+
getNametagsForAddress(addressId?: string): Map<number, string> | undefined;
|
|
2109
2211
|
/**
|
|
2110
2212
|
* Get all registered address nametags
|
|
2111
2213
|
*
|
|
2112
|
-
* @returns Map of
|
|
2214
|
+
* @returns Map of addressId to (nametagIndex -> nametag)
|
|
2113
2215
|
*/
|
|
2114
|
-
getAllAddressNametags(): Map<number, string
|
|
2216
|
+
getAllAddressNametags(): Map<string, Map<number, string>>;
|
|
2217
|
+
/**
|
|
2218
|
+
* Get current address identifier (DIRECT://xxx format)
|
|
2219
|
+
*/
|
|
2220
|
+
private getCurrentAddressId;
|
|
2115
2221
|
/**
|
|
2116
2222
|
* Switch to a different address by index
|
|
2117
2223
|
* This changes the active identity to the derived address at the specified index.
|
|
@@ -2209,6 +2315,13 @@ declare class Sphere {
|
|
|
2209
2315
|
* Check if nametag is registered
|
|
2210
2316
|
*/
|
|
2211
2317
|
hasNametag(): boolean;
|
|
2318
|
+
/**
|
|
2319
|
+
* Get the PROXY address for the current nametag
|
|
2320
|
+
* PROXY addresses are derived from the nametag hash and require
|
|
2321
|
+
* the nametag token to claim funds sent to them
|
|
2322
|
+
* @returns PROXY address string or undefined if no nametag
|
|
2323
|
+
*/
|
|
2324
|
+
getProxyAddress(): string | undefined;
|
|
2212
2325
|
/**
|
|
2213
2326
|
* Register a nametag for the current active address
|
|
2214
2327
|
* Each address can have its own independent nametag
|
|
@@ -2230,6 +2343,7 @@ declare class Sphere {
|
|
|
2230
2343
|
registerNametag(nametag: string): Promise<void>;
|
|
2231
2344
|
/**
|
|
2232
2345
|
* Persist address nametags to storage
|
|
2346
|
+
* Format: { "DIRECT://abc...xyz": { "0": "alice", "1": "alice2" }, ... }
|
|
2233
2347
|
*/
|
|
2234
2348
|
private persistAddressNametags;
|
|
2235
2349
|
/**
|
|
@@ -2259,6 +2373,8 @@ declare class Sphere {
|
|
|
2259
2373
|
isNametagAvailable(nametag: string): Promise<boolean>;
|
|
2260
2374
|
/**
|
|
2261
2375
|
* Load address nametags from storage
|
|
2376
|
+
* Supports new format: { "DIRECT://abc...xyz": { "0": "alice" } }
|
|
2377
|
+
* And legacy format: { "0": "alice" } (migrates to new format on save)
|
|
2262
2378
|
*/
|
|
2263
2379
|
private loadAddressNametags;
|
|
2264
2380
|
/**
|
|
@@ -2266,6 +2382,12 @@ declare class Sphere {
|
|
|
2266
2382
|
* If local nametag exists but not registered on Nostr, re-register it
|
|
2267
2383
|
*/
|
|
2268
2384
|
private syncNametagWithNostr;
|
|
2385
|
+
/**
|
|
2386
|
+
* Recover nametag from Nostr after wallet import
|
|
2387
|
+
* Searches for encrypted nametag events authored by this wallet's pubkey
|
|
2388
|
+
* and decrypts them to restore the nametag association
|
|
2389
|
+
*/
|
|
2390
|
+
private recoverNametagFromNostr;
|
|
2269
2391
|
/**
|
|
2270
2392
|
* Validate nametag format
|
|
2271
2393
|
*/
|