@qntx/wallet 0.4.0 → 0.5.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.
- package/dist/{index-Dhf6wGjQ.d.mts → chains-D_jfwTPT.d.mts} +299 -117
- package/dist/chains.d.mts +14 -0
- package/dist/chains.mjs +70 -0
- package/dist/chains.mjs.map +1 -0
- package/dist/{secret-IcTjjaX0.mjs → channel-ChYtMklb.mjs} +19 -155
- package/dist/channel-ChYtMklb.mjs.map +1 -0
- package/dist/{core-QJ66nLLG.mjs → core-Dmz5SbyJ.mjs} +55 -23
- package/dist/core-Dmz5SbyJ.mjs.map +1 -0
- package/dist/host.d.mts +17 -4
- package/dist/host.mjs +37 -9
- package/dist/host.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/nostr.d.mts +1 -1
- package/dist/nostr.mjs +2 -1
- package/dist/nostr.mjs.map +1 -1
- package/dist/{protocol-D9xBuMzq.mjs → protocol-DvzlUKB8.mjs} +147 -3
- package/dist/protocol-DvzlUKB8.mjs.map +1 -0
- package/dist/protocol.d.mts +3 -3
- package/dist/protocol.mjs +3 -3
- package/dist/secret-BiyX0Hus.mjs +203 -0
- package/dist/secret-BiyX0Hus.mjs.map +1 -0
- package/dist/spark.d.mts +2 -2
- package/dist/{types-D4OUjGVS.d.mts → types-BD9fuAUj.d.mts} +9 -2
- package/dist/types.d.mts +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +19 -7
- package/dist/core-QJ66nLLG.mjs.map +0 -1
- package/dist/protocol-D9xBuMzq.mjs.map +0 -1
- package/dist/secret-IcTjjaX0.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as DerivedNostrKey, b as WalletErrorCode, d as NostrKeyInfo, l as LockReason, m as StatusPayload, s as FactorInfo, x as WalletInfo } from "./types-
|
|
1
|
+
import { a as DerivedNostrKey, b as WalletErrorCode, d as NostrKeyInfo, l as LockReason, m as StatusPayload, s as FactorInfo, x as WalletInfo } from "./types-BD9fuAUj.mjs";
|
|
2
2
|
//#region src/protocol/validate.d.ts
|
|
3
3
|
declare class ValidationError extends Error {
|
|
4
4
|
name: string;
|
|
@@ -34,119 +34,6 @@ declare function union<Vs extends ReadonlyArray<Validator<unknown>>>(...branches
|
|
|
34
34
|
/** Validates a value and returns it, or undefined on a shape mismatch. */
|
|
35
35
|
declare function validate<T>(validator: Validator<T>, value: unknown): T | undefined;
|
|
36
36
|
//#endregion
|
|
37
|
-
//#region src/protocol/core.d.ts
|
|
38
|
-
type MethodSpec<P, R> = {
|
|
39
|
-
readonly session: boolean;
|
|
40
|
-
/** Whether a successful call refreshes the idle timer — presence-bearing methods only. */
|
|
41
|
-
readonly presence: boolean;
|
|
42
|
-
readonly params: Validator<P>;
|
|
43
|
-
readonly result: Validator<R>;
|
|
44
|
-
};
|
|
45
|
-
type Factor = {
|
|
46
|
-
readonly kind: "password";
|
|
47
|
-
readonly password: Uint8Array;
|
|
48
|
-
} | {
|
|
49
|
-
readonly kind: "passkey";
|
|
50
|
-
readonly credentialId: Uint8Array;
|
|
51
|
-
readonly prf: Uint8Array;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* A backup-envelope factor: same shapes as `Factor`, except the passkey arm carries `prfBackup` —
|
|
55
|
-
* the PRF evaluated over `backupSalt`, not the vault or wallet salt.
|
|
56
|
-
*/
|
|
57
|
-
type BackupFactor = {
|
|
58
|
-
readonly kind: "password";
|
|
59
|
-
readonly password: Uint8Array;
|
|
60
|
-
} | {
|
|
61
|
-
readonly kind: "passkey";
|
|
62
|
-
readonly credentialId: Uint8Array;
|
|
63
|
-
readonly prfBackup: Uint8Array;
|
|
64
|
-
};
|
|
65
|
-
declare const walletErrorCode: Validator<WalletErrorCode>;
|
|
66
|
-
/**
|
|
67
|
-
* The result of every "create or import" wallet command: the new wallet's public info plus the
|
|
68
|
-
* session it opened. Creating a wallet derives no protocol keys — modules add keys separately.
|
|
69
|
-
*/
|
|
70
|
-
type CreatedResult = {
|
|
71
|
-
readonly wallet: WalletInfo;
|
|
72
|
-
readonly session: string;
|
|
73
|
-
};
|
|
74
|
-
declare const CORE_METHODS: {
|
|
75
|
-
readonly "vault.unlock": MethodSpec<{
|
|
76
|
-
readonly factor: Factor;
|
|
77
|
-
}, {
|
|
78
|
-
readonly session: string;
|
|
79
|
-
}>;
|
|
80
|
-
readonly "vault.reset": MethodSpec<NullValue, NullValue>;
|
|
81
|
-
readonly "vault.addFactor": MethodSpec<{
|
|
82
|
-
readonly verify: Factor;
|
|
83
|
-
readonly factor: Factor;
|
|
84
|
-
}, FactorInfo>;
|
|
85
|
-
readonly "vault.removeFactor": MethodSpec<{
|
|
86
|
-
readonly verify: Factor;
|
|
87
|
-
readonly id: string;
|
|
88
|
-
}, NullValue>;
|
|
89
|
-
readonly "session.touch": MethodSpec<NullValue, NullValue>;
|
|
90
|
-
readonly "wallet.createWithPasskey": MethodSpec<{
|
|
91
|
-
readonly credentialId: Uint8Array;
|
|
92
|
-
readonly prfWallet: Uint8Array;
|
|
93
|
-
readonly synced: boolean;
|
|
94
|
-
readonly factor?: Factor;
|
|
95
|
-
}, CreatedResult>;
|
|
96
|
-
readonly "wallet.restoreWithPasskey": MethodSpec<{
|
|
97
|
-
readonly credentialId: Uint8Array;
|
|
98
|
-
readonly prfWallet: Uint8Array;
|
|
99
|
-
readonly synced: boolean;
|
|
100
|
-
readonly factor?: Factor;
|
|
101
|
-
}, CreatedResult>;
|
|
102
|
-
readonly "wallet.createMnemonic": MethodSpec<{
|
|
103
|
-
readonly words: 12 | 24;
|
|
104
|
-
readonly factor?: Factor;
|
|
105
|
-
}, {
|
|
106
|
-
readonly draft: string;
|
|
107
|
-
readonly words: Uint8Array;
|
|
108
|
-
readonly quiz: ReadonlyArray<number>;
|
|
109
|
-
}>;
|
|
110
|
-
readonly "wallet.confirmMnemonic": MethodSpec<{
|
|
111
|
-
readonly draft: string;
|
|
112
|
-
readonly answers: ReadonlyArray<Uint8Array>;
|
|
113
|
-
}, CreatedResult>;
|
|
114
|
-
readonly "wallet.discardMnemonic": MethodSpec<{
|
|
115
|
-
readonly draft: string;
|
|
116
|
-
}, NullValue>;
|
|
117
|
-
readonly "backup.enable": MethodSpec<{
|
|
118
|
-
readonly verify: Factor;
|
|
119
|
-
readonly factors: ReadonlyArray<BackupFactor>;
|
|
120
|
-
}, NullValue>;
|
|
121
|
-
readonly "backup.update": MethodSpec<NullValue, {
|
|
122
|
-
readonly envelope: string;
|
|
123
|
-
}>;
|
|
124
|
-
readonly "backup.disable": MethodSpec<NullValue, NullValue>;
|
|
125
|
-
readonly "backup.restore": MethodSpec<{
|
|
126
|
-
readonly envelope: string;
|
|
127
|
-
readonly backupFactor: BackupFactor;
|
|
128
|
-
readonly factor?: Factor;
|
|
129
|
-
}, {
|
|
130
|
-
readonly wallets: ReadonlyArray<WalletInfo>;
|
|
131
|
-
readonly session: string;
|
|
132
|
-
}>;
|
|
133
|
-
readonly "wallet.importMnemonic": MethodSpec<{
|
|
134
|
-
readonly mnemonic: Uint8Array;
|
|
135
|
-
readonly factor?: Factor;
|
|
136
|
-
}, CreatedResult>;
|
|
137
|
-
readonly "wallet.exportMnemonic": MethodSpec<{
|
|
138
|
-
readonly verify: Factor;
|
|
139
|
-
readonly walletId: string;
|
|
140
|
-
}, Uint8Array>;
|
|
141
|
-
readonly "wallet.delete": MethodSpec<{
|
|
142
|
-
readonly verify: Factor;
|
|
143
|
-
readonly walletId: string;
|
|
144
|
-
}, NullValue>;
|
|
145
|
-
readonly "dataKeys.get": MethodSpec<{
|
|
146
|
-
readonly purpose: string;
|
|
147
|
-
}, Uint8Array>;
|
|
148
|
-
};
|
|
149
|
-
//#endregion
|
|
150
37
|
//#region src/protocol/nostr.d.ts
|
|
151
38
|
/**
|
|
152
39
|
* The unsigned event input the kernel signs. `pubkey` is optional: callers may omit it and the
|
|
@@ -650,7 +537,7 @@ declare function requestBytes(value: ProtocolValue): number;
|
|
|
650
537
|
declare function isProtocolValue(value: unknown): value is ProtocolValue;
|
|
651
538
|
declare const METHODS: {
|
|
652
539
|
readonly status: MethodSpec<NullValue, StatusPayload>;
|
|
653
|
-
} & typeof CORE_METHODS & typeof NOSTR_METHODS & typeof SPARK_METHODS;
|
|
540
|
+
} & typeof CORE_METHODS & typeof NOSTR_METHODS & typeof CHAINS_METHODS & typeof SPARK_METHODS;
|
|
654
541
|
type AssertNever<T extends never> = T;
|
|
655
542
|
type MethodTablesDisjoint = [AssertNever<keyof typeof CORE_METHODS & keyof typeof NOSTR_METHODS>, AssertNever<keyof typeof CORE_METHODS & keyof typeof SPARK_METHODS>, AssertNever<keyof typeof NOSTR_METHODS & keyof typeof SPARK_METHODS>];
|
|
656
543
|
type MethodName = keyof typeof METHODS;
|
|
@@ -664,5 +551,300 @@ declare const responseError: Validator<{
|
|
|
664
551
|
retryAt?: number | undefined;
|
|
665
552
|
}>;
|
|
666
553
|
//#endregion
|
|
667
|
-
|
|
668
|
-
|
|
554
|
+
//#region src/protocol/core.d.ts
|
|
555
|
+
type MethodSpec<P, R> = {
|
|
556
|
+
readonly session: boolean;
|
|
557
|
+
/** Whether a successful call refreshes the idle timer — presence-bearing methods only. */
|
|
558
|
+
readonly presence: boolean;
|
|
559
|
+
readonly params: Validator<P>;
|
|
560
|
+
readonly result: Validator<R>;
|
|
561
|
+
};
|
|
562
|
+
/**
|
|
563
|
+
* Vault factor material on the wire. `hardware` carries nothing: the kernel runs the platform
|
|
564
|
+
* keystore ceremony itself, so the main runtime never touches the KEK.
|
|
565
|
+
*/
|
|
566
|
+
type Factor = {
|
|
567
|
+
readonly kind: "hardware";
|
|
568
|
+
} | {
|
|
569
|
+
readonly kind: "password";
|
|
570
|
+
readonly password: Uint8Array;
|
|
571
|
+
} | {
|
|
572
|
+
readonly kind: "passkey";
|
|
573
|
+
readonly credentialId: Uint8Array;
|
|
574
|
+
readonly prf: Uint8Array;
|
|
575
|
+
};
|
|
576
|
+
/** A host-run backup passkey ceremony's evidence: the PRF over `backupSalt` (web). */
|
|
577
|
+
type HostBackupPasskey = {
|
|
578
|
+
readonly kind: "passkey";
|
|
579
|
+
readonly ceremony: "host";
|
|
580
|
+
readonly credentialId: Uint8Array;
|
|
581
|
+
readonly prfBackup: Uint8Array;
|
|
582
|
+
};
|
|
583
|
+
/**
|
|
584
|
+
* A factor that seals a new backup key. On React Native the kernel registers a protection
|
|
585
|
+
* credential (`kernel`) itself and names it; on the web the host hands over its ceremony's
|
|
586
|
+
* evidence.
|
|
587
|
+
*/
|
|
588
|
+
type BackupFactor = {
|
|
589
|
+
readonly kind: "password";
|
|
590
|
+
readonly password: Uint8Array;
|
|
591
|
+
} | HostBackupPasskey | {
|
|
592
|
+
readonly kind: "passkey";
|
|
593
|
+
readonly ceremony: "kernel";
|
|
594
|
+
readonly rpId: string;
|
|
595
|
+
readonly rpName: string;
|
|
596
|
+
readonly backupSalt: string;
|
|
597
|
+
};
|
|
598
|
+
/**
|
|
599
|
+
* A factor that opens a backup envelope. The `kernel` passkey arm asserts one of the envelope's own
|
|
600
|
+
* credentials.
|
|
601
|
+
*/
|
|
602
|
+
type BackupUnlockFactor = {
|
|
603
|
+
readonly kind: "password";
|
|
604
|
+
readonly password: Uint8Array;
|
|
605
|
+
} | HostBackupPasskey | {
|
|
606
|
+
readonly kind: "passkey";
|
|
607
|
+
readonly ceremony: "kernel";
|
|
608
|
+
readonly rpId: string;
|
|
609
|
+
readonly backupSalt: string;
|
|
610
|
+
};
|
|
611
|
+
/**
|
|
612
|
+
* Passkey wallet creation. `host`: the host ran the WebAuthn ceremony and hands over the PRF
|
|
613
|
+
* evidence (web). `kernel`: the kernel runs the platform ceremony itself and nothing secret crosses
|
|
614
|
+
* the channel (React Native). The kernel accepts exactly the shape its platform supports.
|
|
615
|
+
*/
|
|
616
|
+
type CreateWithPasskeyParams = {
|
|
617
|
+
readonly ceremony: "host";
|
|
618
|
+
readonly credentialId: Uint8Array;
|
|
619
|
+
readonly prfWallet: Uint8Array;
|
|
620
|
+
readonly synced: boolean;
|
|
621
|
+
readonly factor?: Factor;
|
|
622
|
+
} | {
|
|
623
|
+
readonly ceremony: "kernel";
|
|
624
|
+
readonly rpId: string;
|
|
625
|
+
readonly rpName: string;
|
|
626
|
+
readonly name: string;
|
|
627
|
+
readonly walletSalt: string;
|
|
628
|
+
readonly factor?: Factor;
|
|
629
|
+
};
|
|
630
|
+
type RestoreWithPasskeyParams = {
|
|
631
|
+
readonly ceremony: "host";
|
|
632
|
+
readonly credentialId: Uint8Array;
|
|
633
|
+
readonly prfWallet: Uint8Array;
|
|
634
|
+
readonly synced: boolean;
|
|
635
|
+
readonly factor?: Factor;
|
|
636
|
+
} | {
|
|
637
|
+
readonly ceremony: "kernel";
|
|
638
|
+
readonly rpId: string;
|
|
639
|
+
readonly walletSalt: string;
|
|
640
|
+
readonly factor?: Factor;
|
|
641
|
+
};
|
|
642
|
+
declare const walletErrorCode: Validator<WalletErrorCode>;
|
|
643
|
+
/**
|
|
644
|
+
* The result of every "create or import" wallet command: the new wallet's public info plus the
|
|
645
|
+
* session it opened. Creating a wallet derives no protocol keys — modules add keys separately.
|
|
646
|
+
*/
|
|
647
|
+
type CreatedResult = {
|
|
648
|
+
readonly wallet: WalletInfo;
|
|
649
|
+
readonly session: string;
|
|
650
|
+
};
|
|
651
|
+
declare const CORE_METHODS: {
|
|
652
|
+
readonly "vault.unlock": MethodSpec<{
|
|
653
|
+
readonly factor: Factor;
|
|
654
|
+
}, {
|
|
655
|
+
readonly session: string;
|
|
656
|
+
}>;
|
|
657
|
+
readonly "vault.reset": MethodSpec<NullValue, NullValue>;
|
|
658
|
+
readonly "vault.addFactor": MethodSpec<{
|
|
659
|
+
readonly verify: Factor;
|
|
660
|
+
readonly factor: Factor;
|
|
661
|
+
}, FactorInfo>;
|
|
662
|
+
readonly "vault.removeFactor": MethodSpec<{
|
|
663
|
+
readonly verify: Factor;
|
|
664
|
+
readonly id: string;
|
|
665
|
+
}, NullValue>;
|
|
666
|
+
readonly "session.touch": MethodSpec<NullValue, NullValue>;
|
|
667
|
+
readonly "wallet.createWithPasskey": MethodSpec<CreateWithPasskeyParams, CreatedResult>;
|
|
668
|
+
readonly "wallet.restoreWithPasskey": MethodSpec<RestoreWithPasskeyParams, CreatedResult>;
|
|
669
|
+
readonly "wallet.createMnemonic": MethodSpec<{
|
|
670
|
+
readonly words: 12 | 24;
|
|
671
|
+
readonly factor?: Factor;
|
|
672
|
+
}, {
|
|
673
|
+
readonly draft: string;
|
|
674
|
+
readonly words: Uint8Array;
|
|
675
|
+
readonly quiz: ReadonlyArray<number>;
|
|
676
|
+
}>;
|
|
677
|
+
readonly "wallet.confirmMnemonic": MethodSpec<{
|
|
678
|
+
readonly draft: string;
|
|
679
|
+
readonly answers: ReadonlyArray<Uint8Array>;
|
|
680
|
+
}, CreatedResult>;
|
|
681
|
+
readonly "wallet.discardMnemonic": MethodSpec<{
|
|
682
|
+
readonly draft: string;
|
|
683
|
+
}, NullValue>;
|
|
684
|
+
readonly "backup.enable": MethodSpec<{
|
|
685
|
+
readonly verify: Factor;
|
|
686
|
+
readonly factors: ReadonlyArray<BackupFactor>;
|
|
687
|
+
}, NullValue>;
|
|
688
|
+
readonly "backup.update": MethodSpec<NullValue, {
|
|
689
|
+
readonly envelope: string;
|
|
690
|
+
}>;
|
|
691
|
+
readonly "backup.disable": MethodSpec<NullValue, NullValue>;
|
|
692
|
+
readonly "backup.restore": MethodSpec<{
|
|
693
|
+
readonly envelope: string;
|
|
694
|
+
readonly backupFactor: BackupUnlockFactor;
|
|
695
|
+
readonly factor?: Factor;
|
|
696
|
+
}, {
|
|
697
|
+
readonly wallets: ReadonlyArray<WalletInfo>;
|
|
698
|
+
readonly session: string;
|
|
699
|
+
}>;
|
|
700
|
+
readonly "wallet.importMnemonic": MethodSpec<{
|
|
701
|
+
readonly mnemonic: Uint8Array;
|
|
702
|
+
readonly factor?: Factor;
|
|
703
|
+
}, CreatedResult>;
|
|
704
|
+
readonly "wallet.exportMnemonic": MethodSpec<{
|
|
705
|
+
readonly verify: Factor;
|
|
706
|
+
readonly walletId: string;
|
|
707
|
+
}, Uint8Array>;
|
|
708
|
+
readonly "wallet.delete": MethodSpec<{
|
|
709
|
+
readonly verify: Factor;
|
|
710
|
+
readonly walletId: string;
|
|
711
|
+
}, NullValue>;
|
|
712
|
+
readonly "dataKeys.get": MethodSpec<{
|
|
713
|
+
readonly purpose: string;
|
|
714
|
+
}, Uint8Array>;
|
|
715
|
+
};
|
|
716
|
+
//#endregion
|
|
717
|
+
//#region src/protocol/chains.d.ts
|
|
718
|
+
type ChainTemplate = "evm.bip44" | "solana.bip44-change" | "btc.bip44" | "btc.bip49" | "btc.bip84" | "btc.bip86";
|
|
719
|
+
type ChainAccountsParams = {
|
|
720
|
+
readonly walletId: string;
|
|
721
|
+
readonly groupIndex: number;
|
|
722
|
+
readonly template: ChainTemplate;
|
|
723
|
+
readonly network: string;
|
|
724
|
+
};
|
|
725
|
+
type ChainAccount = {
|
|
726
|
+
readonly template: "evm.bip44";
|
|
727
|
+
readonly network: string;
|
|
728
|
+
readonly address: string;
|
|
729
|
+
} | {
|
|
730
|
+
readonly template: "solana.bip44-change";
|
|
731
|
+
readonly network: string;
|
|
732
|
+
readonly address: string;
|
|
733
|
+
} | {
|
|
734
|
+
readonly template: "btc.bip44" | "btc.bip49" | "btc.bip84" | "btc.bip86";
|
|
735
|
+
readonly network: string;
|
|
736
|
+
readonly xpub: string;
|
|
737
|
+
/** Master-key fingerprint as 8 lowercase hex chars (PSBT bip32Derivation). */
|
|
738
|
+
readonly fingerprint: string;
|
|
739
|
+
/** Account derivation path, e.g. "m/84'/0'/0'". */
|
|
740
|
+
readonly path: string;
|
|
741
|
+
};
|
|
742
|
+
type AccountRef = {
|
|
743
|
+
readonly kind: "hd";
|
|
744
|
+
readonly walletId: string;
|
|
745
|
+
readonly groupIndex: number;
|
|
746
|
+
readonly template: ChainTemplate;
|
|
747
|
+
} | {
|
|
748
|
+
readonly kind: "imported";
|
|
749
|
+
readonly keyId: string;
|
|
750
|
+
readonly family: "evm" | "solana" | "bitcoin";
|
|
751
|
+
};
|
|
752
|
+
type EvmAccessListEntryWire = {
|
|
753
|
+
readonly address: string;
|
|
754
|
+
readonly storageKeys: ReadonlyArray<string>;
|
|
755
|
+
};
|
|
756
|
+
type EvmTransactionBase = {
|
|
757
|
+
readonly chainId: number;
|
|
758
|
+
readonly nonce: number;
|
|
759
|
+
readonly gas: string;
|
|
760
|
+
readonly value: string;
|
|
761
|
+
readonly data: string;
|
|
762
|
+
readonly to?: string;
|
|
763
|
+
};
|
|
764
|
+
type EvmTransactionWire = (EvmTransactionBase & {
|
|
765
|
+
readonly type: "legacy";
|
|
766
|
+
readonly gasPrice: string;
|
|
767
|
+
}) | (EvmTransactionBase & {
|
|
768
|
+
readonly type: "eip2930";
|
|
769
|
+
readonly gasPrice: string;
|
|
770
|
+
readonly accessList: ReadonlyArray<EvmAccessListEntryWire>;
|
|
771
|
+
}) | (EvmTransactionBase & {
|
|
772
|
+
readonly type: "eip1559";
|
|
773
|
+
readonly maxFeePerGas: string;
|
|
774
|
+
readonly maxPriorityFeePerGas: string;
|
|
775
|
+
readonly accessList: ReadonlyArray<EvmAccessListEntryWire>;
|
|
776
|
+
});
|
|
777
|
+
/** `chain.sign`'s request — the wire mirror of @qntx/wallet-chains `SignRequest`. */
|
|
778
|
+
type ChainSignRequest = {
|
|
779
|
+
readonly kind: "evm.transaction";
|
|
780
|
+
readonly network: string;
|
|
781
|
+
readonly account: AccountRef;
|
|
782
|
+
readonly tx: EvmTransactionWire;
|
|
783
|
+
} | {
|
|
784
|
+
readonly kind: "evm.personal-message";
|
|
785
|
+
readonly network: string;
|
|
786
|
+
readonly account: AccountRef;
|
|
787
|
+
readonly message: Uint8Array;
|
|
788
|
+
} | {
|
|
789
|
+
readonly kind: "evm.typed-data";
|
|
790
|
+
readonly network: string;
|
|
791
|
+
readonly account: AccountRef;
|
|
792
|
+
readonly typedData: string;
|
|
793
|
+
} | {
|
|
794
|
+
readonly kind: "solana.transaction";
|
|
795
|
+
readonly network: string;
|
|
796
|
+
readonly account: AccountRef;
|
|
797
|
+
readonly message: Uint8Array;
|
|
798
|
+
readonly lookupTables?: ReadonlyArray<{
|
|
799
|
+
readonly address: string;
|
|
800
|
+
readonly addresses: ReadonlyArray<string>;
|
|
801
|
+
}>;
|
|
802
|
+
} | {
|
|
803
|
+
readonly kind: "solana.message";
|
|
804
|
+
readonly network: string;
|
|
805
|
+
readonly account: AccountRef;
|
|
806
|
+
readonly message: Uint8Array;
|
|
807
|
+
readonly format: "raw";
|
|
808
|
+
} | {
|
|
809
|
+
readonly kind: "bitcoin.psbt";
|
|
810
|
+
readonly network: string;
|
|
811
|
+
readonly account: AccountRef;
|
|
812
|
+
readonly psbt: Uint8Array;
|
|
813
|
+
readonly sign: ReadonlyArray<number>;
|
|
814
|
+
} | {
|
|
815
|
+
readonly kind: "bitcoin.message";
|
|
816
|
+
readonly network: string;
|
|
817
|
+
readonly account: AccountRef;
|
|
818
|
+
readonly address: string;
|
|
819
|
+
readonly message: string;
|
|
820
|
+
readonly format: "bip322-simple" | "legacy";
|
|
821
|
+
readonly change: 0 | 1;
|
|
822
|
+
readonly index: number;
|
|
823
|
+
};
|
|
824
|
+
type ChainSignResult = {
|
|
825
|
+
readonly kind: "evm.transaction";
|
|
826
|
+
readonly signedTransaction: Uint8Array;
|
|
827
|
+
} | {
|
|
828
|
+
readonly kind: "evm.personal-message" | "evm.typed-data";
|
|
829
|
+
readonly signature: Uint8Array;
|
|
830
|
+
} | {
|
|
831
|
+
readonly kind: "solana.transaction" | "solana.message";
|
|
832
|
+
readonly signature: Uint8Array;
|
|
833
|
+
} | {
|
|
834
|
+
readonly kind: "bitcoin.psbt";
|
|
835
|
+
readonly signedPsbt: Uint8Array;
|
|
836
|
+
} | {
|
|
837
|
+
readonly kind: "bitcoin.message";
|
|
838
|
+
readonly signature: string;
|
|
839
|
+
};
|
|
840
|
+
type ChainSignParams = {
|
|
841
|
+
readonly request: ChainSignRequest;
|
|
842
|
+
readonly verify: Factor;
|
|
843
|
+
};
|
|
844
|
+
declare const CHAINS_METHODS: {
|
|
845
|
+
readonly "wallet.accounts": MethodSpec<ChainAccountsParams, ChainAccount>;
|
|
846
|
+
readonly "chain.sign": MethodSpec<ChainSignParams, ChainSignResult>;
|
|
847
|
+
};
|
|
848
|
+
//#endregion
|
|
849
|
+
export { PreparedTransfer as $, isProtocolValue as A, opt as At, backupEnvelopeFactor as B, PROTOCOL_VERSION as C, arr as Ct, Response as D, literal as Dt, Request as E, int as Et, BackupEnvelopeWire as F, FrostSignJob as G, backupHeader as H, BackupHeaderWallet as I, OperatorCommitment as J, HtlcTimeoutSignRequest as K, BackupHeaderWire as L, requestBytes as M, str as Mt, responseError as N, union as Nt, ResultOf as O, nullValue as Ot, BackupEnvelopeFactor as P, validate as Pt, PreparedLightningReceive as Q, BackupInfo as R, NullValue as S, Validator as St, ProtocolValue as T, bytes as Tt, backupInfo as U, backupEnvelopeText as V, FrostAggregateJob as W, PrepareTransferRequest as X, PrepareClaimRequest as Y, PreparedClaim as Z, KernelEvent as _, Rumor as _t, ChainSignResult as a, SparkApprovalSummary as at, MethodName as b, UnwrapResult as bt, BackupUnlockFactor as c, SparkLeafKey as ct, CreatedResult as d, StaticDepositClaimResult as dt, PreparedTransferLeaf as et, Factor as f, StaticDepositClaimStatement as ft, ErrorPayload as g, NostrImportInput as gt, walletErrorCode as h, NostrExportFormat as ht, ChainSignRequest as i, SparkAccountRef as it, kernelEvent as j, record as jt, UNATTRIBUTED_ID as k, obj as kt, CORE_METHODS as l, SparkNetwork as lt, RestoreWithPasskeyParams as m, NOSTR_METHODS as mt, ChainAccount as n, SigningCommitment as nt, ChainTemplate as o, SparkApproveIntent as ot, MethodSpec as p, KeyResult as pt, IdentityStatement as q, ChainAccountsParams as r, SigningTarget as rt, BackupFactor as s, SparkKey as st, CHAINS_METHODS as t, SPARK_METHODS as tt, CreateWithPasskeyParams as u, StaticDepositClaimRequest as ut, MAX_REQUEST_BYTES as v, SignedEvent as vt, ParamsOf as w, bool as wt, MethodTablesDisjoint as x, ValidationError as xt, METHODS as y, UnsignedEventInput as yt, backupEnvelope as z };
|
|
850
|
+
//# sourceMappingURL=chains-D_jfwTPT.d.mts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { h as UnlockFactor, v as Wallet } from "./types-BD9fuAUj.mjs";
|
|
2
|
+
import { a as ChainSignResult, i as ChainSignRequest, n as ChainAccount, o as ChainTemplate, r as ChainAccountsParams } from "./chains-D_jfwTPT.mjs";
|
|
3
|
+
//#region src/chains/index.d.ts
|
|
4
|
+
export type ChainsApi = {
|
|
5
|
+
readonly account: (params: ChainAccountsParams) => Promise<ChainAccount>;
|
|
6
|
+
readonly sign: (params: {
|
|
7
|
+
readonly request: ChainSignRequest;
|
|
8
|
+
readonly verify: UnlockFactor;
|
|
9
|
+
}) => Promise<ChainSignResult>;
|
|
10
|
+
};
|
|
11
|
+
export declare function chains(wallet: Wallet): ChainsApi;
|
|
12
|
+
//#endregion
|
|
13
|
+
export type { ChainAccount, ChainAccountsParams, ChainSignRequest, ChainSignResult, ChainTemplate };
|
|
14
|
+
//# sourceMappingURL=chains.d.mts.map
|
package/dist/chains.mjs
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { n as integrity } from "./channel-ChYtMklb.mjs";
|
|
2
|
+
import { t as internalsOf } from "./internal-LBHal13j.mjs";
|
|
3
|
+
import { bitcoinAddressFromXpub, verifyBitcoinMessage, verifyBitcoinPsbtSignatures } from "@qntx/wallet-chains/bitcoin";
|
|
4
|
+
import { recoverEvmSigner } from "@qntx/wallet-chains/evm";
|
|
5
|
+
import { verifySolanaSignature } from "@qntx/wallet-chains/solana";
|
|
6
|
+
//#region src/chains/index.ts
|
|
7
|
+
/**
|
|
8
|
+
* The chains module of @qntx/wallet: `chains(wallet)` returns the wallet's chain API. `account`
|
|
9
|
+
* calls the kernel's `wallet.accounts`; `sign` calls `chain.sign` and then verifies the returned
|
|
10
|
+
* signature against the account address — a kernel that answers with someone else's signature fails
|
|
11
|
+
* closed with `integrity`.
|
|
12
|
+
*/
|
|
13
|
+
/** Whether the kernel's signature belongs to the account it was asked to sign for. */
|
|
14
|
+
const checkSigner = (request, result, account) => {
|
|
15
|
+
if (request.kind === "bitcoin.psbt" || request.kind === "bitcoin.message") {
|
|
16
|
+
if (!("xpub" in account)) throw integrity("chain account has no xpub");
|
|
17
|
+
if (request.kind === "bitcoin.psbt" && result.kind === "bitcoin.psbt") {
|
|
18
|
+
if (!verifyBitcoinPsbtSignatures(result.signedPsbt, request.sign, account.xpub, account.template, request.network)) throw integrity("psbt signatures do not verify for the account");
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (request.kind === "bitcoin.message" && result.kind === "bitcoin.message") {
|
|
22
|
+
if (bitcoinAddressFromXpub(account.xpub, account.template, request.network, request.change, request.index) !== request.address || !verifyBitcoinMessage(request.address, request.message, result.signature, request.network)) throw integrity("message signature does not verify for the account");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
throw integrity("result kind does not match the request");
|
|
26
|
+
}
|
|
27
|
+
if (!("address" in account)) throw integrity("chain account has no address");
|
|
28
|
+
if (request.kind.startsWith("evm.")) {
|
|
29
|
+
if (result.kind !== "evm.transaction" && result.kind !== "evm.personal-message" && result.kind !== "evm.typed-data") throw integrity("result kind does not match the request");
|
|
30
|
+
if (recoverEvmSigner(request, result).toLowerCase() !== account.address.toLowerCase()) throw integrity("signer does not match the account");
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if ((request.kind === "solana.transaction" || request.kind === "solana.message") && (result.kind === "solana.transaction" || result.kind === "solana.message") && !verifySolanaSignature(request.message, result.signature, account.address)) throw integrity("signature does not verify for the account");
|
|
34
|
+
};
|
|
35
|
+
function createChainsApi(internals) {
|
|
36
|
+
return {
|
|
37
|
+
account: async (params) => internals.call("wallet.accounts", params),
|
|
38
|
+
sign: async (params) => internals.withVerifying(async () => {
|
|
39
|
+
const verify = await internals.resolveFactor(params.verify, []);
|
|
40
|
+
const result = await internals.call("chain.sign", {
|
|
41
|
+
request: params.request,
|
|
42
|
+
verify
|
|
43
|
+
});
|
|
44
|
+
if (params.request.account.kind === "hd") {
|
|
45
|
+
const account = await internals.call("wallet.accounts", {
|
|
46
|
+
walletId: params.request.account.walletId,
|
|
47
|
+
groupIndex: params.request.account.groupIndex,
|
|
48
|
+
template: params.request.account.template,
|
|
49
|
+
network: params.request.network
|
|
50
|
+
});
|
|
51
|
+
checkSigner(params.request, result, account);
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
})
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const apis = /* @__PURE__ */ new WeakMap();
|
|
58
|
+
function chains(wallet) {
|
|
59
|
+
const internals = internalsOf(wallet);
|
|
60
|
+
let api = apis.get(wallet);
|
|
61
|
+
if (api === void 0) {
|
|
62
|
+
api = createChainsApi(internals);
|
|
63
|
+
apis.set(wallet, api);
|
|
64
|
+
}
|
|
65
|
+
return api;
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { chains };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=chains.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chains.mjs","names":[],"sources":["../src/chains/index.ts"],"sourcesContent":["/**\n * The chains module of @qntx/wallet: `chains(wallet)` returns the wallet's chain API. `account`\n * calls the kernel's `wallet.accounts`; `sign` calls `chain.sign` and then verifies the returned\n * signature against the account address — a kernel that answers with someone else's signature fails\n * closed with `integrity`.\n */\nimport {\n bitcoinAddressFromXpub,\n verifyBitcoinMessage,\n verifyBitcoinPsbtSignatures,\n} from \"@qntx/wallet-chains/bitcoin\";\nimport { recoverEvmSigner } from \"@qntx/wallet-chains/evm\";\nimport { verifySolanaSignature } from \"@qntx/wallet-chains/solana\";\n\nimport { integrity } from \"../channel.ts\";\nimport { internalsOf } from \"../internal.ts\";\nimport type { WalletInternals } from \"../internal.ts\";\nimport type {\n ChainAccount,\n ChainAccountsParams,\n ChainSignRequest,\n ChainSignResult,\n} from \"../protocol/chains.ts\";\nimport type { UnlockFactor, Wallet } from \"../types.ts\";\n\nexport type {\n ChainAccount,\n ChainAccountsParams,\n ChainSignRequest,\n ChainSignResult,\n ChainTemplate,\n} from \"../protocol/chains.ts\";\n\nexport type ChainsApi = {\n readonly account: (params: ChainAccountsParams) => Promise<ChainAccount>;\n readonly sign: (params: {\n readonly request: ChainSignRequest;\n readonly verify: UnlockFactor;\n }) => Promise<ChainSignResult>;\n};\n\n/** Whether the kernel's signature belongs to the account it was asked to sign for. */\nconst checkSigner = (request: ChainSignRequest, result: ChainSignResult, account: ChainAccount) => {\n if (request.kind === \"bitcoin.psbt\" || request.kind === \"bitcoin.message\") {\n if (!(\"xpub\" in account)) {\n throw integrity(\"chain account has no xpub\");\n }\n if (request.kind === \"bitcoin.psbt\" && result.kind === \"bitcoin.psbt\") {\n if (\n !verifyBitcoinPsbtSignatures(\n result.signedPsbt,\n request.sign,\n account.xpub,\n account.template,\n request.network,\n )\n ) {\n throw integrity(\"psbt signatures do not verify for the account\");\n }\n return;\n }\n if (request.kind === \"bitcoin.message\" && result.kind === \"bitcoin.message\") {\n const derived = bitcoinAddressFromXpub(\n account.xpub,\n account.template,\n request.network,\n request.change,\n request.index,\n );\n if (\n derived !== request.address ||\n !verifyBitcoinMessage(request.address, request.message, result.signature, request.network)\n ) {\n throw integrity(\"message signature does not verify for the account\");\n }\n return;\n }\n throw integrity(\"result kind does not match the request\");\n }\n if (!(\"address\" in account)) {\n throw integrity(\"chain account has no address\");\n }\n if (request.kind.startsWith(\"evm.\")) {\n if (\n result.kind !== \"evm.transaction\" &&\n result.kind !== \"evm.personal-message\" &&\n result.kind !== \"evm.typed-data\"\n ) {\n throw integrity(\"result kind does not match the request\");\n }\n const signer = recoverEvmSigner(request, result);\n if (signer.toLowerCase() !== account.address.toLowerCase()) {\n throw integrity(\"signer does not match the account\");\n }\n return;\n }\n if (\n (request.kind === \"solana.transaction\" || request.kind === \"solana.message\") &&\n (result.kind === \"solana.transaction\" || result.kind === \"solana.message\") &&\n !verifySolanaSignature(request.message, result.signature, account.address)\n ) {\n throw integrity(\"signature does not verify for the account\");\n }\n};\n\nfunction createChainsApi(internals: WalletInternals): ChainsApi {\n return {\n account: async (params) => internals.call(\"wallet.accounts\", params),\n sign: async (params) =>\n internals.withVerifying(async () => {\n const transfer: ArrayBuffer[] = [];\n const verify = await internals.resolveFactor(params.verify, transfer);\n const result = await internals.call(\"chain.sign\", { request: params.request, verify });\n if (params.request.account.kind === \"hd\") {\n const account = await internals.call(\"wallet.accounts\", {\n walletId: params.request.account.walletId,\n groupIndex: params.request.account.groupIndex,\n template: params.request.account.template,\n network: params.request.network,\n });\n checkSigner(params.request, result, account);\n }\n return result;\n }),\n };\n}\n\nconst apis = new WeakMap<Wallet, ChainsApi>();\n\nexport function chains(wallet: Wallet): ChainsApi {\n const internals = internalsOf(wallet);\n let api = apis.get(wallet);\n if (api === undefined) {\n api = createChainsApi(internals);\n apis.set(wallet, api);\n }\n return api;\n}\n"],"mappings":";;;;;;;;;;;;;AA0CA,MAAM,eAAe,SAA2B,QAAyB,YAA0B;CACjG,IAAI,QAAQ,SAAS,kBAAkB,QAAQ,SAAS,mBAAmB;EACzE,IAAI,EAAE,UAAU,UACd,MAAM,UAAU,2BAA2B;EAE7C,IAAI,QAAQ,SAAS,kBAAkB,OAAO,SAAS,gBAAgB;GACrE,IACE,CAAC,4BACC,OAAO,YACP,QAAQ,MACR,QAAQ,MACR,QAAQ,UACR,QAAQ,OACV,GAEA,MAAM,UAAU,+CAA+C;GAEjE;EACF;EACA,IAAI,QAAQ,SAAS,qBAAqB,OAAO,SAAS,mBAAmB;GAQ3E,IAPgB,uBACd,QAAQ,MACR,QAAQ,UACR,QAAQ,SACR,QAAQ,QACR,QAAQ,KAGF,MAAM,QAAQ,WACpB,CAAC,qBAAqB,QAAQ,SAAS,QAAQ,SAAS,OAAO,WAAW,QAAQ,OAAO,GAEzF,MAAM,UAAU,mDAAmD;GAErE;EACF;EACA,MAAM,UAAU,wCAAwC;CAC1D;CACA,IAAI,EAAE,aAAa,UACjB,MAAM,UAAU,8BAA8B;CAEhD,IAAI,QAAQ,KAAK,WAAW,MAAM,GAAG;EACnC,IACE,OAAO,SAAS,qBAChB,OAAO,SAAS,0BAChB,OAAO,SAAS,kBAEhB,MAAM,UAAU,wCAAwC;EAG1D,IADe,iBAAiB,SAAS,MAChC,CAAC,CAAC,YAAY,MAAM,QAAQ,QAAQ,YAAY,GACvD,MAAM,UAAU,mCAAmC;EAErD;CACF;CACA,KACG,QAAQ,SAAS,wBAAwB,QAAQ,SAAS,sBAC1D,OAAO,SAAS,wBAAwB,OAAO,SAAS,qBACzD,CAAC,sBAAsB,QAAQ,SAAS,OAAO,WAAW,QAAQ,OAAO,GAEzE,MAAM,UAAU,2CAA2C;AAE/D;AAEA,SAAS,gBAAgB,WAAuC;CAC9D,OAAO;EACL,SAAS,OAAO,WAAW,UAAU,KAAK,mBAAmB,MAAM;EACnE,MAAM,OAAO,WACX,UAAU,cAAc,YAAY;GAElC,MAAM,SAAS,MAAM,UAAU,cAAc,OAAO,QAAQ,CAAO,CAAC;GACpE,MAAM,SAAS,MAAM,UAAU,KAAK,cAAc;IAAE,SAAS,OAAO;IAAS;GAAO,CAAC;GACrF,IAAI,OAAO,QAAQ,QAAQ,SAAS,MAAM;IACxC,MAAM,UAAU,MAAM,UAAU,KAAK,mBAAmB;KACtD,UAAU,OAAO,QAAQ,QAAQ;KACjC,YAAY,OAAO,QAAQ,QAAQ;KACnC,UAAU,OAAO,QAAQ,QAAQ;KACjC,SAAS,OAAO,QAAQ;IAC1B,CAAC;IACD,YAAY,OAAO,SAAS,QAAQ,OAAO;GAC7C;GACA,OAAO;EACT,CAAC;CACL;AACF;AAEA,MAAM,uBAAO,IAAI,QAA2B;AAE5C,SAAgB,OAAO,QAA2B;CAChD,MAAM,YAAY,YAAY,MAAM;CACpC,IAAI,MAAM,KAAK,IAAI,MAAM;CACzB,IAAI,QAAQ,KAAA,GAAW;EACrB,MAAM,gBAAgB,SAAS;EAC/B,KAAK,IAAI,QAAQ,GAAG;CACtB;CACA,OAAO;AACT"}
|