@bsv/sdk 1.3.8 → 1.3.10
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/cjs/package.json +1 -1
- package/dist/cjs/src/auth/Peer.js +1 -1
- package/dist/cjs/src/auth/Peer.js.map +1 -1
- package/dist/cjs/src/auth/certificates/Certificate.js.map +1 -1
- package/dist/cjs/src/auth/certificates/MasterCertificate.js +3 -3
- package/dist/cjs/src/auth/certificates/MasterCertificate.js.map +1 -1
- package/dist/cjs/src/auth/certificates/VerifiableCertificate.js +1 -1
- package/dist/cjs/src/auth/certificates/VerifiableCertificate.js.map +1 -1
- package/dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js +12 -0
- package/dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js.map +1 -1
- package/dist/cjs/src/auth/clients/AuthFetch.js.map +1 -1
- package/dist/cjs/src/auth/utils/createNonce.js +9 -3
- package/dist/cjs/src/auth/utils/createNonce.js.map +1 -1
- package/dist/cjs/src/auth/utils/getVerifiableCertificates.js.map +1 -1
- package/dist/cjs/src/auth/utils/validateCertificates.js.map +1 -1
- package/dist/cjs/src/auth/utils/verifyNonce.js +3 -2
- package/dist/cjs/src/auth/utils/verifyNonce.js.map +1 -1
- package/dist/cjs/src/overlay-tools/OverlayAdminTokenTemplate.js.map +1 -1
- package/dist/cjs/src/script/templates/PushDrop.js +1 -1
- package/dist/cjs/src/script/templates/PushDrop.js.map +1 -1
- package/dist/cjs/src/wallet/ProtoWallet.js +10 -58
- package/dist/cjs/src/wallet/ProtoWallet.js.map +1 -1
- package/dist/cjs/src/wallet/WalletClient.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/HTTPWalletJSON.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/window.CWI.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/auth/Peer.js +1 -1
- package/dist/esm/src/auth/Peer.js.map +1 -1
- package/dist/esm/src/auth/certificates/Certificate.js +1 -1
- package/dist/esm/src/auth/certificates/Certificate.js.map +1 -1
- package/dist/esm/src/auth/certificates/MasterCertificate.js +3 -3
- package/dist/esm/src/auth/certificates/MasterCertificate.js.map +1 -1
- package/dist/esm/src/auth/certificates/VerifiableCertificate.js +1 -1
- package/dist/esm/src/auth/certificates/VerifiableCertificate.js.map +1 -1
- package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js +12 -0
- package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js.map +1 -1
- package/dist/esm/src/auth/clients/AuthFetch.js.map +1 -1
- package/dist/esm/src/auth/utils/createNonce.js +9 -3
- package/dist/esm/src/auth/utils/createNonce.js.map +1 -1
- package/dist/esm/src/auth/utils/getVerifiableCertificates.js.map +1 -1
- package/dist/esm/src/auth/utils/validateCertificates.js.map +1 -1
- package/dist/esm/src/auth/utils/verifyNonce.js +3 -2
- package/dist/esm/src/auth/utils/verifyNonce.js.map +1 -1
- package/dist/esm/src/overlay-tools/OverlayAdminTokenTemplate.js.map +1 -1
- package/dist/esm/src/script/templates/PushDrop.js +1 -1
- package/dist/esm/src/script/templates/PushDrop.js.map +1 -1
- package/dist/esm/src/wallet/ProtoWallet.js +10 -58
- package/dist/esm/src/wallet/ProtoWallet.js.map +1 -1
- package/dist/esm/src/wallet/WalletClient.js.map +1 -1
- package/dist/esm/src/wallet/substrates/HTTPWalletJSON.js.map +1 -1
- package/dist/esm/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
- package/dist/esm/src/wallet/substrates/window.CWI.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/auth/Peer.d.ts +3 -3
- package/dist/types/src/auth/Peer.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/Certificate.d.ts +2 -2
- package/dist/types/src/auth/certificates/Certificate.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/MasterCertificate.d.ts +7 -7
- package/dist/types/src/auth/certificates/MasterCertificate.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts +3 -3
- package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/__tests/CompletedProtoWallet.d.ts +6 -2
- package/dist/types/src/auth/certificates/__tests/CompletedProtoWallet.d.ts.map +1 -1
- package/dist/types/src/auth/clients/AuthFetch.d.ts +2 -2
- package/dist/types/src/auth/clients/AuthFetch.d.ts.map +1 -1
- package/dist/types/src/auth/utils/createNonce.d.ts +4 -3
- package/dist/types/src/auth/utils/createNonce.d.ts.map +1 -1
- package/dist/types/src/auth/utils/getVerifiableCertificates.d.ts +2 -2
- package/dist/types/src/auth/utils/getVerifiableCertificates.d.ts.map +1 -1
- package/dist/types/src/auth/utils/validateCertificates.d.ts +2 -2
- package/dist/types/src/auth/utils/validateCertificates.d.ts.map +1 -1
- package/dist/types/src/auth/utils/verifyNonce.d.ts +3 -2
- package/dist/types/src/auth/utils/verifyNonce.d.ts.map +1 -1
- package/dist/types/src/overlay-tools/OverlayAdminTokenTemplate.d.ts +2 -2
- package/dist/types/src/overlay-tools/OverlayAdminTokenTemplate.d.ts.map +1 -1
- package/dist/types/src/script/templates/PushDrop.d.ts +4 -4
- package/dist/types/src/script/templates/PushDrop.d.ts.map +1 -1
- package/dist/types/src/wallet/ProtoWallet.d.ts +12 -24
- package/dist/types/src/wallet/ProtoWallet.d.ts.map +1 -1
- package/dist/types/src/wallet/Wallet.interfaces.d.ts +5 -18
- package/dist/types/src/wallet/Wallet.interfaces.d.ts.map +1 -1
- package/dist/types/src/wallet/WalletClient.d.ts +4 -4
- package/dist/types/src/wallet/WalletClient.d.ts.map +1 -1
- package/dist/types/src/wallet/substrates/HTTPWalletJSON.d.ts +2 -2
- package/dist/types/src/wallet/substrates/HTTPWalletJSON.d.ts.map +1 -1
- package/dist/types/src/wallet/substrates/WalletWireProcessor.d.ts +3 -3
- package/dist/types/src/wallet/substrates/WalletWireProcessor.d.ts.map +1 -1
- package/dist/types/src/wallet/substrates/WalletWireTransceiver.d.ts +2 -2
- package/dist/types/src/wallet/substrates/WalletWireTransceiver.d.ts.map +1 -1
- package/dist/types/src/wallet/substrates/XDM.d.ts +2 -2
- package/dist/types/src/wallet/substrates/XDM.d.ts.map +1 -1
- package/dist/types/src/wallet/substrates/window.CWI.d.ts +2 -2
- package/dist/types/src/wallet/substrates/window.CWI.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/docs/auth.md +80 -40
- package/docs/overlay-tools.md +4 -4
- package/docs/script.md +5 -5
- package/docs/wallet-substrates.md +11 -11
- package/docs/wallet.md +300 -360
- package/package.json +1 -1
- package/src/auth/Peer.ts +4 -4
- package/src/auth/certificates/Certificate.ts +4 -3
- package/src/auth/certificates/MasterCertificate.ts +8 -8
- package/src/auth/certificates/VerifiableCertificate.ts +3 -3
- package/src/auth/certificates/__tests/CompletedProtoWallet.ts +14 -3
- package/src/auth/clients/AuthFetch.ts +3 -3
- package/src/auth/utils/__tests/cryptononce.test.ts +42 -7
- package/src/auth/utils/createNonce.ts +10 -4
- package/src/auth/utils/getVerifiableCertificates.ts +2 -2
- package/src/auth/utils/validateCertificates.ts +2 -2
- package/src/auth/utils/verifyNonce.ts +4 -3
- package/src/overlay-tools/OverlayAdminTokenTemplate.ts +2 -2
- package/src/script/templates/PushDrop.ts +4 -4
- package/src/wallet/ProtoWallet.ts +21 -87
- package/src/wallet/Wallet.interfaces.ts +5 -19
- package/src/wallet/WalletClient.ts +33 -33
- package/src/wallet/__tests/ProtoWallet.test.ts +0 -31
- package/src/wallet/substrates/HTTPWalletJSON.ts +3 -3
- package/src/wallet/substrates/WalletWireProcessor.ts +3 -3
- package/src/wallet/substrates/WalletWireTransceiver.ts +2 -2
- package/src/wallet/substrates/XDM.ts +3 -3
- package/src/wallet/substrates/__tests/WalletWire.integration.test.ts +0 -104
- package/src/wallet/substrates/window.CWI.ts +5 -5
|
@@ -916,8 +916,10 @@ export interface GetPublicKeyResult {
|
|
|
916
916
|
}
|
|
917
917
|
|
|
918
918
|
/**
|
|
919
|
-
* The
|
|
920
|
-
*
|
|
919
|
+
* The Wallet interface defines a wallet capable of various tasks including transaction creation and signing,
|
|
920
|
+
* encryption, decryption, identity certificate management, identity verification, and communication
|
|
921
|
+
* with applications as per the BRC standards. This interface allows applications to interact with
|
|
922
|
+
* the wallet for a range of functionalities aligned with the Babbage architectural principles.
|
|
921
923
|
*
|
|
922
924
|
* Error Handling
|
|
923
925
|
*
|
|
@@ -926,7 +928,7 @@ export interface GetPublicKeyResult {
|
|
|
926
928
|
* Serialization layers can rely on the `isError` property being unique to error objects to
|
|
927
929
|
* deserialize and rethrow `WalletErrorObject` conforming objects.
|
|
928
930
|
*/
|
|
929
|
-
export interface
|
|
931
|
+
export interface WalletInterface {
|
|
930
932
|
/**
|
|
931
933
|
* Retrieves a derived or identity public key based on the requested protocol, key ID, counterparty, and other factors.
|
|
932
934
|
*
|
|
@@ -1035,22 +1037,6 @@ export interface ProtoWalletApi {
|
|
|
1035
1037
|
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
1036
1038
|
) => Promise<VerifySignatureResult>
|
|
1037
1039
|
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
/**
|
|
1041
|
-
* The Wallet interface defines a wallet capable of various tasks including transaction creation and signing,
|
|
1042
|
-
* encryption, decryption, identity certificate management, identity verification, and communication
|
|
1043
|
-
* with applications as per the BRC standards. This interface allows applications to interact with
|
|
1044
|
-
* the wallet for a range of functionalities aligned with the Babbage architectural principles.
|
|
1045
|
-
*
|
|
1046
|
-
* Error Handling
|
|
1047
|
-
*
|
|
1048
|
-
* Every method of the `Wallet` interface has a return value of the form `Promise<object>`.
|
|
1049
|
-
* When an error occurs, an exception object may be thrown which must conform to the `WalletErrorObject` interface.
|
|
1050
|
-
* Serialization layers can rely on the `isError` property being unique to error objects to
|
|
1051
|
-
* deserialize and rethrow `WalletErrorObject` conforming objects.
|
|
1052
|
-
*/
|
|
1053
|
-
export interface Wallet extends ProtoWalletApi {
|
|
1054
1040
|
/**
|
|
1055
1041
|
* Creates a new Bitcoin transaction based on the provided inputs, outputs, labels, locks, and other options.
|
|
1056
1042
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AcquireCertificateArgs, AcquireCertificateResult, Base64String, BasketStringUnder300Bytes, BEEF, BooleanDefaultFalse, BooleanDefaultTrue, Byte, CertificateFieldNameUnder50Bytes, CreateActionArgs, CreateActionResult, DescriptionString5to50Bytes, DiscoverCertificatesResult, EntityIconURLStringMax500Bytes, EntityNameStringMax100Bytes, HexString, InternalizeActionArgs, ISOTimestampString, KeyIDStringUnder800Bytes, LabelStringUnder300Bytes, ListActionsArgs, ListActionsResult, ListCertificatesResult, ListOutputsArgs, ListOutputsResult, OriginatorDomainNameStringUnder250Bytes, OutpointString, OutputTagStringUnder300Bytes, PositiveInteger, PositiveIntegerDefault10Max10000, PositiveIntegerMax10, PositiveIntegerOrZero, ProtocolString5To400Bytes, ProveCertificateArgs, ProveCertificateResult, PubKeyHex, SatoshiValue, SecurityLevel, SignActionArgs, SignActionResult, TXIDHexString, VersionString7To30Bytes,
|
|
1
|
+
import { AcquireCertificateArgs, AcquireCertificateResult, Base64String, BasketStringUnder300Bytes, BEEF, BooleanDefaultFalse, BooleanDefaultTrue, Byte, CertificateFieldNameUnder50Bytes, CreateActionArgs, CreateActionResult, DescriptionString5to50Bytes, DiscoverCertificatesResult, EntityIconURLStringMax500Bytes, EntityNameStringMax100Bytes, HexString, InternalizeActionArgs, ISOTimestampString, KeyIDStringUnder800Bytes, LabelStringUnder300Bytes, ListActionsArgs, ListActionsResult, ListCertificatesResult, ListOutputsArgs, ListOutputsResult, OriginatorDomainNameStringUnder250Bytes, OutpointString, OutputTagStringUnder300Bytes, PositiveInteger, PositiveIntegerDefault10Max10000, PositiveIntegerMax10, PositiveIntegerOrZero, ProtocolString5To400Bytes, ProveCertificateArgs, ProveCertificateResult, PubKeyHex, SatoshiValue, SecurityLevel, SignActionArgs, SignActionResult, TXIDHexString, VersionString7To30Bytes, WalletInterface, AuthenticatedResult } from './Wallet.interfaces.js'
|
|
2
2
|
import WindowCWISubstrate from './substrates/window.CWI.js'
|
|
3
3
|
import XDMSubstrate from './substrates/XDM.js'
|
|
4
4
|
import WalletWireTransceiver from './substrates/WalletWireTransceiver.js'
|
|
@@ -10,10 +10,10 @@ const MAX_XDM_RESPONSE_WAIT = 200
|
|
|
10
10
|
/**
|
|
11
11
|
* The SDK is how applications communicate with wallets over a communications substrate.
|
|
12
12
|
*/
|
|
13
|
-
export default class WalletClient implements
|
|
14
|
-
public substrate: 'auto' |
|
|
13
|
+
export default class WalletClient implements WalletInterface {
|
|
14
|
+
public substrate: 'auto' | WalletInterface
|
|
15
15
|
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
16
|
-
constructor (substrate: 'auto' | 'Cicada' | 'XDM' | 'window.CWI' | 'json-api' |
|
|
16
|
+
constructor (substrate: 'auto' | 'Cicada' | 'XDM' | 'window.CWI' | 'json-api' | WalletInterface = 'auto', originator?: OriginatorDomainNameStringUnder250Bytes) {
|
|
17
17
|
if (substrate === 'Cicada') substrate = new WalletWireTransceiver(new HTTPWalletWire(originator))
|
|
18
18
|
if (substrate === 'window.CWI') substrate = new WindowCWISubstrate()
|
|
19
19
|
if (substrate === 'XDM') substrate = new XDMSubstrate()
|
|
@@ -26,7 +26,7 @@ export default class WalletClient implements Wallet {
|
|
|
26
26
|
if (typeof this.substrate === 'object') {
|
|
27
27
|
return // substrate is already connected
|
|
28
28
|
}
|
|
29
|
-
let sub:
|
|
29
|
+
let sub: WalletInterface
|
|
30
30
|
const checkSub = async (timeout?: number) => {
|
|
31
31
|
let result
|
|
32
32
|
if (typeof timeout === 'number') {
|
|
@@ -70,140 +70,140 @@ export default class WalletClient implements Wallet {
|
|
|
70
70
|
|
|
71
71
|
async createAction (args: CreateActionArgs): Promise<CreateActionResult> {
|
|
72
72
|
await this.connectToSubstrate()
|
|
73
|
-
return await (this.substrate as
|
|
73
|
+
return await (this.substrate as WalletInterface).createAction(args, this.originator)
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
async signAction (args: SignActionArgs): Promise<SignActionResult> {
|
|
77
77
|
await this.connectToSubstrate()
|
|
78
|
-
return await (this.substrate as
|
|
78
|
+
return await (this.substrate as WalletInterface).signAction(args, this.originator)
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
async abortAction (args: { reference: Base64String }): Promise<{ aborted: true }> {
|
|
82
82
|
await this.connectToSubstrate()
|
|
83
|
-
return await (this.substrate as
|
|
83
|
+
return await (this.substrate as WalletInterface).abortAction(args, this.originator)
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
async listActions (args: ListActionsArgs): Promise<ListActionsResult> {
|
|
87
87
|
await this.connectToSubstrate()
|
|
88
|
-
return await (this.substrate as
|
|
88
|
+
return await (this.substrate as WalletInterface).listActions(args, this.originator)
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
async internalizeAction (args: InternalizeActionArgs): Promise<{ accepted: true }> {
|
|
92
92
|
await this.connectToSubstrate()
|
|
93
|
-
return await (this.substrate as
|
|
93
|
+
return await (this.substrate as WalletInterface).internalizeAction(args, this.originator)
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
async listOutputs (args: ListOutputsArgs): Promise<ListOutputsResult> {
|
|
97
97
|
await this.connectToSubstrate()
|
|
98
|
-
return await (this.substrate as
|
|
98
|
+
return await (this.substrate as WalletInterface).listOutputs(args, this.originator)
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
async relinquishOutput (args: { basket: BasketStringUnder300Bytes, output: OutpointString }): Promise<{ relinquished: true }> {
|
|
102
102
|
await this.connectToSubstrate()
|
|
103
|
-
return await (this.substrate as
|
|
103
|
+
return await (this.substrate as WalletInterface).relinquishOutput(args, this.originator)
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
async getPublicKey (args: { identityKey?: true, protocolID?: [SecurityLevel, ProtocolString5To400Bytes], keyID?: KeyIDStringUnder800Bytes, privileged?: BooleanDefaultFalse, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', forSelf?: BooleanDefaultFalse }): Promise<{ publicKey: PubKeyHex }> {
|
|
107
107
|
await this.connectToSubstrate()
|
|
108
|
-
return await (this.substrate as
|
|
108
|
+
return await (this.substrate as WalletInterface).getPublicKey(args, this.originator)
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
async revealCounterpartyKeyLinkage (args: { counterparty: PubKeyHex, verifier: PubKeyHex, privilegedReason?: DescriptionString5to50Bytes, privileged?: BooleanDefaultFalse }): Promise<{ prover: PubKeyHex, verifier: PubKeyHex, counterparty: PubKeyHex, revelationTime: ISOTimestampString, encryptedLinkage: Byte[], encryptedLinkageProof: Byte[] }> {
|
|
112
112
|
await this.connectToSubstrate()
|
|
113
|
-
return await (this.substrate as
|
|
113
|
+
return await (this.substrate as WalletInterface).revealCounterpartyKeyLinkage(args, this.originator)
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
async revealSpecificKeyLinkage (args: { counterparty: PubKeyHex, verifier: PubKeyHex, protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, privileged?: BooleanDefaultFalse }): Promise<{ prover: PubKeyHex, verifier: PubKeyHex, counterparty: PubKeyHex, protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, encryptedLinkage: Byte[], encryptedLinkageProof: Byte[], proofType: Byte }> {
|
|
117
117
|
await this.connectToSubstrate()
|
|
118
|
-
return await (this.substrate as
|
|
118
|
+
return await (this.substrate as WalletInterface).revealSpecificKeyLinkage(args, this.originator)
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
async encrypt (args: { plaintext: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', privileged?: BooleanDefaultFalse }): Promise<{ ciphertext: Byte[] }> {
|
|
122
122
|
await this.connectToSubstrate()
|
|
123
|
-
return await (this.substrate as
|
|
123
|
+
return await (this.substrate as WalletInterface).encrypt(args, this.originator)
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
async decrypt (args: { ciphertext: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', privileged?: BooleanDefaultFalse }): Promise<{ plaintext: Byte[] }> {
|
|
127
|
-
return await (this.substrate as
|
|
127
|
+
return await (this.substrate as WalletInterface).decrypt(args, this.originator)
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
async createHmac (args: { data: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', privileged?: BooleanDefaultFalse }): Promise<{ hmac: Byte[] }> {
|
|
131
131
|
await this.connectToSubstrate()
|
|
132
|
-
return await (this.substrate as
|
|
132
|
+
return await (this.substrate as WalletInterface).createHmac(args, this.originator)
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
async verifyHmac (args: { data: Byte[], hmac: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', privileged?: BooleanDefaultFalse }): Promise<{ valid: true }> {
|
|
136
136
|
await this.connectToSubstrate()
|
|
137
|
-
return await (this.substrate as
|
|
137
|
+
return await (this.substrate as WalletInterface).verifyHmac(args, this.originator)
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
async createSignature (args: { data?: Byte[], hashToDirectlySign?: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', privileged?: BooleanDefaultFalse }): Promise<{ signature: Byte[] }> {
|
|
141
141
|
await this.connectToSubstrate()
|
|
142
|
-
return await (this.substrate as
|
|
142
|
+
return await (this.substrate as WalletInterface).createSignature(args, this.originator)
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
async verifySignature (args: { data?: Byte[], hashToDirectlyVerify?: Byte[], signature: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', forSelf?: BooleanDefaultFalse, privileged?: BooleanDefaultFalse }): Promise<{ valid: true }> {
|
|
146
146
|
await this.connectToSubstrate()
|
|
147
|
-
return await (this.substrate as
|
|
147
|
+
return await (this.substrate as WalletInterface).verifySignature(args, this.originator)
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
async acquireCertificate (args: AcquireCertificateArgs): Promise<AcquireCertificateResult> {
|
|
151
151
|
await this.connectToSubstrate()
|
|
152
|
-
return await (this.substrate as
|
|
152
|
+
return await (this.substrate as WalletInterface).acquireCertificate(args, this.originator)
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
async listCertificates (args: { certifiers: PubKeyHex[], types: Base64String[], limit?: PositiveIntegerDefault10Max10000, offset?: PositiveIntegerOrZero, privileged?: BooleanDefaultFalse, privilegedReason?: DescriptionString5to50Bytes }): Promise<ListCertificatesResult> {
|
|
156
156
|
await this.connectToSubstrate()
|
|
157
|
-
return await (this.substrate as
|
|
157
|
+
return await (this.substrate as WalletInterface).listCertificates(args, this.originator)
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
async proveCertificate (args: ProveCertificateArgs): Promise<ProveCertificateResult> {
|
|
161
161
|
await this.connectToSubstrate()
|
|
162
|
-
return await (this.substrate as
|
|
162
|
+
return await (this.substrate as WalletInterface).proveCertificate(args, this.originator)
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
async relinquishCertificate (args: { type: Base64String, serialNumber: Base64String, certifier: PubKeyHex }): Promise<{ relinquished: true }> {
|
|
166
166
|
await this.connectToSubstrate()
|
|
167
|
-
return await (this.substrate as
|
|
167
|
+
return await (this.substrate as WalletInterface).relinquishCertificate(args, this.originator)
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
async discoverByIdentityKey (args: { identityKey: PubKeyHex, limit?: PositiveIntegerDefault10Max10000, offset?: PositiveIntegerOrZero }): Promise<DiscoverCertificatesResult> {
|
|
171
171
|
await this.connectToSubstrate()
|
|
172
|
-
return await (this.substrate as
|
|
172
|
+
return await (this.substrate as WalletInterface).discoverByIdentityKey(args, this.originator)
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
async discoverByAttributes (args: { attributes: Record<CertificateFieldNameUnder50Bytes, string>, limit?: PositiveIntegerDefault10Max10000, offset?: PositiveIntegerOrZero }): Promise<DiscoverCertificatesResult> {
|
|
176
176
|
await this.connectToSubstrate()
|
|
177
|
-
return await (this.substrate as
|
|
177
|
+
return await (this.substrate as WalletInterface).discoverByAttributes(args, this.originator)
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
async isAuthenticated (args: {} = {}): Promise<AuthenticatedResult> {
|
|
181
181
|
await this.connectToSubstrate()
|
|
182
|
-
return await (this.substrate as
|
|
182
|
+
return await (this.substrate as WalletInterface).isAuthenticated(args, this.originator)
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
async waitForAuthentication (args: {} = {}): Promise<{ authenticated: true }> {
|
|
186
186
|
await this.connectToSubstrate()
|
|
187
|
-
return await (this.substrate as
|
|
187
|
+
return await (this.substrate as WalletInterface).waitForAuthentication(args, this.originator)
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
async getHeight (args: {} = {}): Promise<{ height: PositiveInteger }> {
|
|
191
191
|
await this.connectToSubstrate()
|
|
192
|
-
return await (this.substrate as
|
|
192
|
+
return await (this.substrate as WalletInterface).getHeight(args, this.originator)
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
async getHeaderForHeight (args: { height: PositiveInteger }): Promise<{ header: HexString }> {
|
|
196
196
|
await this.connectToSubstrate()
|
|
197
|
-
return await (this.substrate as
|
|
197
|
+
return await (this.substrate as WalletInterface).getHeaderForHeight(args, this.originator)
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
async getNetwork (args: {} = {}): Promise<{ network: 'mainnet' | 'testnet' }> {
|
|
201
201
|
await this.connectToSubstrate()
|
|
202
|
-
return await (this.substrate as
|
|
202
|
+
return await (this.substrate as WalletInterface).getNetwork(args, this.originator)
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
async getVersion (args: {} = {}): Promise<{ version: VersionString7To30Bytes }> {
|
|
206
206
|
await this.connectToSubstrate()
|
|
207
|
-
return await (this.substrate as
|
|
207
|
+
return await (this.substrate as WalletInterface).getVersion(args, this.originator)
|
|
208
208
|
}
|
|
209
209
|
}
|
|
@@ -7,37 +7,6 @@ describe('ProtoWallet', () => {
|
|
|
7
7
|
it('Throws when functions are not supported', async () => {
|
|
8
8
|
const wallet = new ProtoWallet('anyone')
|
|
9
9
|
})
|
|
10
|
-
it('Throws the privileged error when the privileged flag is set', async () => {
|
|
11
|
-
const wallet = new ProtoWallet('anyone')
|
|
12
|
-
const privilegedError = 'ProtoWallet is a single-keyring wallet, operating without context about whether its configured keyring is privileged.'
|
|
13
|
-
await expect(() => {
|
|
14
|
-
return (wallet as any).encrypt({ privileged: true })
|
|
15
|
-
}).rejects.toThrow(new Error(privilegedError))
|
|
16
|
-
await expect(() => {
|
|
17
|
-
return (wallet as any).decrypt({ privileged: true })
|
|
18
|
-
}).rejects.toThrow(new Error(privilegedError))
|
|
19
|
-
await expect(() => {
|
|
20
|
-
return (wallet as any).createSignature({ privileged: true })
|
|
21
|
-
}).rejects.toThrow(new Error(privilegedError))
|
|
22
|
-
await expect(() => {
|
|
23
|
-
return (wallet as any).verifySignature({ privileged: true })
|
|
24
|
-
}).rejects.toThrow(new Error(privilegedError))
|
|
25
|
-
await expect(() => {
|
|
26
|
-
return (wallet as any).createHmac({ privileged: true })
|
|
27
|
-
}).rejects.toThrow(new Error(privilegedError))
|
|
28
|
-
await expect(() => {
|
|
29
|
-
return (wallet as any).verifyHmac({ privileged: true })
|
|
30
|
-
}).rejects.toThrow(new Error(privilegedError))
|
|
31
|
-
await expect(() => {
|
|
32
|
-
return (wallet as any).getPublicKey({ privileged: true })
|
|
33
|
-
}).rejects.toThrow(new Error(privilegedError))
|
|
34
|
-
await expect(() => {
|
|
35
|
-
return (wallet as any).revealCounterpartyKeyLinkage({ privileged: true })
|
|
36
|
-
}).rejects.toThrow(new Error(privilegedError))
|
|
37
|
-
await expect(() => {
|
|
38
|
-
return (wallet as any).revealSpecificKeyLinkage({ privileged: true })
|
|
39
|
-
}).rejects.toThrow(new Error(privilegedError))
|
|
40
|
-
})
|
|
41
10
|
it('Validates the BRC-3 compliance vector', async () => {
|
|
42
11
|
const wallet = new ProtoWallet('anyone')
|
|
43
12
|
const { valid } = await wallet.verifySignature({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WalletInterface, CreateActionArgs, OriginatorDomainNameStringUnder250Bytes, CreateActionResult, BooleanDefaultTrue, AcquireCertificateArgs, AcquireCertificateResult, Base64String, BasketStringUnder300Bytes, BooleanDefaultFalse, Byte, CertificateFieldNameUnder50Bytes, DescriptionString5to50Bytes, DiscoverCertificatesResult, EntityIconURLStringMax500Bytes, EntityNameStringMax100Bytes, HexString, InternalizeActionArgs, ISOTimestampString, KeyIDStringUnder800Bytes, ListActionsArgs, ListActionsResult, ListCertificatesResult, ListOutputsArgs, ListOutputsResult, OutpointString, PositiveInteger, PositiveIntegerDefault10Max10000, PositiveIntegerMax10, PositiveIntegerOrZero, ProtocolString5To400Bytes, ProveCertificateArgs, ProveCertificateResult, PubKeyHex, SecurityLevel, SignActionArgs, SignActionResult, VersionString7To30Bytes } from '../Wallet.interfaces.js'
|
|
2
2
|
|
|
3
|
-
export default class HTTPWalletJSON implements
|
|
3
|
+
export default class HTTPWalletJSON implements WalletInterface {
|
|
4
4
|
baseUrl: string
|
|
5
5
|
httpClient: typeof fetch
|
|
6
6
|
originator: OriginatorDomainNameStringUnder250Bytes | undefined
|
|
@@ -23,7 +23,7 @@ export default class HTTPWalletJSON implements Wallet {
|
|
|
23
23
|
})).json()
|
|
24
24
|
return response
|
|
25
25
|
} catch (error) {
|
|
26
|
-
console.log({ 'HTTPWalletJSON': { call, args, error }})
|
|
26
|
+
console.log({ 'HTTPWalletJSON': { call, args, error } })
|
|
27
27
|
throw error
|
|
28
28
|
}
|
|
29
29
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WalletInterface } from '../Wallet.interfaces.js'
|
|
2
2
|
import WalletWire from './WalletWire.js'
|
|
3
3
|
import { Utils } from '../../primitives/index.js'
|
|
4
4
|
import calls from './WalletWireCalls.js'
|
|
@@ -9,9 +9,9 @@ import { SecurityLevel } from '../Wallet.interfaces.js'
|
|
|
9
9
|
* Processes incoming wallet calls received over a wallet wire, with a given wallet.
|
|
10
10
|
*/
|
|
11
11
|
export default class WalletWireProcessor implements WalletWire {
|
|
12
|
-
wallet:
|
|
12
|
+
wallet: WalletInterface
|
|
13
13
|
|
|
14
|
-
constructor(wallet:
|
|
14
|
+
constructor(wallet: WalletInterface) {
|
|
15
15
|
this.wallet = wallet
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AcquireCertificateArgs, AcquireCertificateResult, SecurityLevel, Base64String, BasketStringUnder300Bytes, BEEF, BooleanDefaultFalse, BooleanDefaultTrue, Byte, CertificateFieldNameUnder50Bytes, CreateActionArgs, CreateActionResult, DescriptionString5to50Bytes, DiscoverCertificatesResult, EntityIconURLStringMax500Bytes, EntityNameStringMax100Bytes, HexString, InternalizeActionArgs, ISOTimestampString, KeyIDStringUnder800Bytes, LabelStringUnder300Bytes, ListActionsArgs, ListActionsResult, ListCertificatesResult, ListOutputsArgs, ListOutputsResult, OriginatorDomainNameStringUnder250Bytes, OutpointString, OutputTagStringUnder300Bytes, PositiveInteger, PositiveIntegerDefault10Max10000, PositiveIntegerMax10, PositiveIntegerOrZero, ProtocolString5To400Bytes, ProveCertificateArgs, ProveCertificateResult, PubKeyHex, SatoshiValue, SignActionArgs, SignActionResult, TXIDHexString, VersionString7To30Bytes,
|
|
1
|
+
import { AcquireCertificateArgs, AcquireCertificateResult, SecurityLevel, Base64String, BasketStringUnder300Bytes, BEEF, BooleanDefaultFalse, BooleanDefaultTrue, Byte, CertificateFieldNameUnder50Bytes, CreateActionArgs, CreateActionResult, DescriptionString5to50Bytes, DiscoverCertificatesResult, EntityIconURLStringMax500Bytes, EntityNameStringMax100Bytes, HexString, InternalizeActionArgs, ISOTimestampString, KeyIDStringUnder800Bytes, LabelStringUnder300Bytes, ListActionsArgs, ListActionsResult, ListCertificatesResult, ListOutputsArgs, ListOutputsResult, OriginatorDomainNameStringUnder250Bytes, OutpointString, OutputTagStringUnder300Bytes, PositiveInteger, PositiveIntegerDefault10Max10000, PositiveIntegerMax10, PositiveIntegerOrZero, ProtocolString5To400Bytes, ProveCertificateArgs, ProveCertificateResult, PubKeyHex, SatoshiValue, SignActionArgs, SignActionResult, TXIDHexString, VersionString7To30Bytes, WalletInterface } from '../Wallet.interfaces.js'
|
|
2
2
|
import WalletWire from './WalletWire.js'
|
|
3
3
|
import { Certificate } from '../../auth/index.js'
|
|
4
4
|
import { Utils } from '../../primitives/index.js'
|
|
@@ -8,7 +8,7 @@ import { WalletError } from '../WalletError.js'
|
|
|
8
8
|
/**
|
|
9
9
|
* A way to make remote calls to a wallet over a wallet wire.
|
|
10
10
|
*/
|
|
11
|
-
export default class WalletWireTransceiver implements
|
|
11
|
+
export default class WalletWireTransceiver implements WalletInterface {
|
|
12
12
|
wire: WalletWire
|
|
13
13
|
|
|
14
14
|
constructor(wire: WalletWire) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Base64String, BasketStringUnder300Bytes, BEEF, BooleanDefaultFalse, BooleanDefaultTrue, Byte, CertificateFieldNameUnder50Bytes, DescriptionString5to50Bytes, EntityIconURLStringMax500Bytes, EntityNameStringMax100Bytes, HexString, ISOTimestampString, KeyIDStringUnder800Bytes, LabelStringUnder300Bytes, OriginatorDomainNameStringUnder250Bytes, OutpointString, OutputTagStringUnder300Bytes, PositiveInteger, PositiveIntegerDefault10Max10000, PositiveIntegerMax10, PositiveIntegerOrZero, ProtocolString5To400Bytes, PubKeyHex, SatoshiValue, SecurityLevel, TXIDHexString, VersionString7To30Bytes,
|
|
1
|
+
import { Base64String, BasketStringUnder300Bytes, BEEF, BooleanDefaultFalse, BooleanDefaultTrue, Byte, CertificateFieldNameUnder50Bytes, DescriptionString5to50Bytes, EntityIconURLStringMax500Bytes, EntityNameStringMax100Bytes, HexString, ISOTimestampString, KeyIDStringUnder800Bytes, LabelStringUnder300Bytes, OriginatorDomainNameStringUnder250Bytes, OutpointString, OutputTagStringUnder300Bytes, PositiveInteger, PositiveIntegerDefault10Max10000, PositiveIntegerMax10, PositiveIntegerOrZero, ProtocolString5To400Bytes, PubKeyHex, SatoshiValue, SecurityLevel, TXIDHexString, VersionString7To30Bytes, WalletInterface } from '../Wallet.interfaces.js'
|
|
2
2
|
import { Utils, Random } from '../../primitives/index.js'
|
|
3
3
|
import { WalletError } from '../WalletError.js'
|
|
4
4
|
import { CallType } from 'mod.js'
|
|
@@ -6,9 +6,9 @@ import { CallType } from 'mod.js'
|
|
|
6
6
|
/**
|
|
7
7
|
* Facilitates wallet operations over cross-document messaging.
|
|
8
8
|
*/
|
|
9
|
-
export default class XDMSubstrate implements
|
|
9
|
+
export default class XDMSubstrate implements WalletInterface {
|
|
10
10
|
private readonly domain: string
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
constructor(domain: string = '*') {
|
|
13
13
|
if (typeof window !== 'object') {
|
|
14
14
|
throw new Error('The XDM substrate requires a global window object.')
|
|
@@ -60,47 +60,6 @@ describe('WalletWire Integration Tests', () => {
|
|
|
60
60
|
return (wallet as any).discoverByAttributes()
|
|
61
61
|
}).rejects.toThrow()
|
|
62
62
|
})
|
|
63
|
-
it('Throws the privileged error when the privileged flag is set', async () => {
|
|
64
|
-
const wallet = new WalletWireTransceiver(new WalletWireProcessor(new ProtoWallet('anyone')))
|
|
65
|
-
const privilegedError = 'ProtoWallet is a single-keyring wallet, operating without context about whether its configured keyring is privileged.'
|
|
66
|
-
const saneParams = {
|
|
67
|
-
protocolID: [0, 'hello world'],
|
|
68
|
-
keyID: '123123123',
|
|
69
|
-
plaintext: [0, 1, 3],
|
|
70
|
-
ciphertext: [3, 4, 5],
|
|
71
|
-
data: [1, 3, 5],
|
|
72
|
-
hmac: [1, 3, 5],
|
|
73
|
-
signature: [1, 3, 5],
|
|
74
|
-
counterparty: 'self'
|
|
75
|
-
}
|
|
76
|
-
await expect(() => {
|
|
77
|
-
return (wallet as any).encrypt({ ...saneParams, privileged: true })
|
|
78
|
-
}).rejects.toThrow(new Error(privilegedError))
|
|
79
|
-
await expect(() => {
|
|
80
|
-
return (wallet as any).decrypt({ ...saneParams, privileged: true })
|
|
81
|
-
}).rejects.toThrow(new Error(privilegedError))
|
|
82
|
-
await expect(() => {
|
|
83
|
-
return (wallet as any).createSignature({ ...saneParams, privileged: true })
|
|
84
|
-
}).rejects.toThrow(new Error(privilegedError))
|
|
85
|
-
await expect(() => {
|
|
86
|
-
return (wallet as any).verifySignature({ ...saneParams, privileged: true })
|
|
87
|
-
}).rejects.toThrow(new Error(privilegedError))
|
|
88
|
-
await expect(() => {
|
|
89
|
-
return (wallet as any).createHmac({ ...saneParams, privileged: true })
|
|
90
|
-
}).rejects.toThrow(new Error(privilegedError))
|
|
91
|
-
await expect(() => {
|
|
92
|
-
return (wallet as any).verifyHmac({ ...saneParams, privileged: true })
|
|
93
|
-
}).rejects.toThrow(new Error(privilegedError))
|
|
94
|
-
await expect(() => {
|
|
95
|
-
return (wallet as any).getPublicKey({ ...saneParams, privileged: true })
|
|
96
|
-
}).rejects.toThrow(new Error(privilegedError))
|
|
97
|
-
await expect(() => {
|
|
98
|
-
return (wallet as any).revealCounterpartyKeyLinkage({ ...saneParams, privileged: true })
|
|
99
|
-
}).rejects.toThrow(new Error(privilegedError))
|
|
100
|
-
await expect(() => {
|
|
101
|
-
return (wallet as any).revealSpecificKeyLinkage({ ...saneParams, privileged: true })
|
|
102
|
-
}).rejects.toThrow(new Error(privilegedError))
|
|
103
|
-
})
|
|
104
63
|
it('Validates the BRC-3 compliance vector', async () => {
|
|
105
64
|
const wallet = new WalletWireTransceiver(new WalletWireProcessor(new ProtoWallet('anyone')))
|
|
106
65
|
const { valid } = await wallet.verifySignature({
|
|
@@ -356,13 +315,6 @@ describe('WalletWire Integration Tests', () => {
|
|
|
356
315
|
counterparty: counterpartyKey.toPublicKey().toString()
|
|
357
316
|
})).rejects.toThrow()
|
|
358
317
|
})
|
|
359
|
-
it('Returns the expected version, network, and authentication status', async () => {
|
|
360
|
-
const wallet = new WalletWireTransceiver(new WalletWireProcessor(new ProtoWallet('anyone')))
|
|
361
|
-
expect(await wallet.getVersion({})).toEqual({ version: 'proto-1.0.0' })
|
|
362
|
-
expect(await wallet.getNetwork({})).toEqual({ network: 'mainnet' })
|
|
363
|
-
expect(await wallet.isAuthenticated({})).toEqual({ authenticated: true })
|
|
364
|
-
expect(await wallet.waitForAuthentication({})).toEqual({ authenticated: true })
|
|
365
|
-
})
|
|
366
318
|
it('Uses anyone for creating signatures and self for other operations if no counterparty is provided', async () => {
|
|
367
319
|
const userKey = PrivateKey.fromRandom()
|
|
368
320
|
const user = new WalletWireTransceiver(new WalletWireProcessor(new ProtoWallet(userKey)))
|
|
@@ -1132,16 +1084,6 @@ describe('WalletWire Integration Tests', () => {
|
|
|
1132
1084
|
expect(typeof result.publicKey).toBe('string')
|
|
1133
1085
|
expect(result.publicKey.length).toBe(66)
|
|
1134
1086
|
})
|
|
1135
|
-
|
|
1136
|
-
it('should throw an error for privileged operation without permission', async () => {
|
|
1137
|
-
const wallet = createTestWalletWire(new ProtoWallet(PrivateKey.fromRandom()))
|
|
1138
|
-
const args = {
|
|
1139
|
-
identityKey: true as true,
|
|
1140
|
-
privileged: true,
|
|
1141
|
-
privilegedReason: 'Test privileged operation'
|
|
1142
|
-
}
|
|
1143
|
-
await expect(wallet.getPublicKey(args)).rejects.toThrow()
|
|
1144
|
-
})
|
|
1145
1087
|
})
|
|
1146
1088
|
|
|
1147
1089
|
describe('encrypt and decrypt', () => {
|
|
@@ -1304,54 +1246,8 @@ describe('WalletWire Integration Tests', () => {
|
|
|
1304
1246
|
const expectedLinkage = proverKey.deriveSharedSecret(counterpartyKey.toPublicKey()).encode(true)
|
|
1305
1247
|
expect(decryptedResult.plaintext).toEqual(expectedLinkage)
|
|
1306
1248
|
})
|
|
1307
|
-
|
|
1308
|
-
it('should throw an error when trying to reveal linkage without privilege', async () => {
|
|
1309
|
-
const proverKey = PrivateKey.fromRandom()
|
|
1310
|
-
const counterpartyKey = PrivateKey.fromRandom()
|
|
1311
|
-
const verifierKey = PrivateKey.fromRandom()
|
|
1312
|
-
|
|
1313
|
-
const proverWallet = createTestWalletWire(new ProtoWallet(proverKey))
|
|
1314
|
-
|
|
1315
|
-
const args = {
|
|
1316
|
-
counterparty: counterpartyKey.toPublicKey().toString(),
|
|
1317
|
-
verifier: verifierKey.toPublicKey().toString(),
|
|
1318
|
-
privileged: true
|
|
1319
|
-
}
|
|
1320
|
-
|
|
1321
|
-
await expect(proverWallet.revealCounterpartyKeyLinkage(args)).rejects.toThrow()
|
|
1322
|
-
})
|
|
1323
|
-
})
|
|
1324
|
-
|
|
1325
|
-
describe('getVersion and getNetwork', () => {
|
|
1326
|
-
it('should return the correct version', async () => {
|
|
1327
|
-
const wallet = createTestWalletWire(new ProtoWallet('anyone'))
|
|
1328
|
-
const result = await wallet.getVersion({})
|
|
1329
|
-
expect(result).toHaveProperty('version')
|
|
1330
|
-
expect(typeof result.version).toBe('string')
|
|
1331
|
-
})
|
|
1332
|
-
|
|
1333
|
-
it('should return the correct network', async () => {
|
|
1334
|
-
const wallet = createTestWalletWire(new ProtoWallet('anyone'))
|
|
1335
|
-
const result = await wallet.getNetwork({})
|
|
1336
|
-
expect(result).toHaveProperty('network')
|
|
1337
|
-
expect(['mainnet', 'testnet']).toContain(result.network)
|
|
1338
|
-
})
|
|
1339
1249
|
})
|
|
1340
1250
|
|
|
1341
|
-
describe('isAuthenticated and waitForAuthentication', () => {
|
|
1342
|
-
it('should return authentication status', async () => {
|
|
1343
|
-
const wallet = createTestWalletWire(new ProtoWallet('anyone'))
|
|
1344
|
-
const result = await wallet.isAuthenticated({})
|
|
1345
|
-
expect(result).toHaveProperty('authenticated')
|
|
1346
|
-
expect(typeof result.authenticated).toBe('boolean')
|
|
1347
|
-
})
|
|
1348
|
-
|
|
1349
|
-
it('should wait for authentication', async () => {
|
|
1350
|
-
const wallet = createTestWalletWire(new ProtoWallet('anyone'))
|
|
1351
|
-
const result = await wallet.waitForAuthentication({})
|
|
1352
|
-
expect(result).toEqual({ authenticated: true })
|
|
1353
|
-
})
|
|
1354
|
-
})
|
|
1355
1251
|
describe('acquireCertificate', () => {
|
|
1356
1252
|
it('should acquire a certificate with valid inputs', async () => {
|
|
1357
1253
|
// Mock the acquireCertificate method
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Base64String, BasketStringUnder300Bytes, BEEF, BooleanDefaultFalse, BooleanDefaultTrue, Byte, CertificateFieldNameUnder50Bytes, DescriptionString5to50Bytes, EntityIconURLStringMax500Bytes, EntityNameStringMax100Bytes, HexString, ISOTimestampString, KeyIDStringUnder800Bytes, LabelStringUnder300Bytes, OriginatorDomainNameStringUnder250Bytes, OutpointString, OutputTagStringUnder300Bytes, PositiveInteger, PositiveIntegerDefault10Max10000, PositiveIntegerMax10, PositiveIntegerOrZero, ProtocolString5To400Bytes, PubKeyHex, SatoshiValue, SecurityLevel, TXIDHexString, VersionString7To30Bytes,
|
|
1
|
+
import { Base64String, BasketStringUnder300Bytes, BEEF, BooleanDefaultFalse, BooleanDefaultTrue, Byte, CertificateFieldNameUnder50Bytes, DescriptionString5to50Bytes, EntityIconURLStringMax500Bytes, EntityNameStringMax100Bytes, HexString, ISOTimestampString, KeyIDStringUnder800Bytes, LabelStringUnder300Bytes, OriginatorDomainNameStringUnder250Bytes, OutpointString, OutputTagStringUnder300Bytes, PositiveInteger, PositiveIntegerDefault10Max10000, PositiveIntegerMax10, PositiveIntegerOrZero, ProtocolString5To400Bytes, PubKeyHex, SatoshiValue, SecurityLevel, TXIDHexString, VersionString7To30Bytes, WalletInterface } from '../Wallet.interfaces.js'
|
|
2
2
|
|
|
3
3
|
declare const window: {
|
|
4
|
-
CWI?:
|
|
4
|
+
CWI?: WalletInterface
|
|
5
5
|
} & Window
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Facilitates wallet operations over the window.CWI interface.
|
|
9
9
|
*/
|
|
10
|
-
export default class WindowCWISubstrate implements
|
|
11
|
-
private CWI:
|
|
10
|
+
export default class WindowCWISubstrate implements WalletInterface {
|
|
11
|
+
private CWI: WalletInterface
|
|
12
12
|
constructor() {
|
|
13
13
|
if (typeof window !== 'object') {
|
|
14
14
|
throw new Error('The window.CWI substrate requires a global window object.')
|
|
@@ -16,7 +16,7 @@ export default class WindowCWISubstrate implements Wallet {
|
|
|
16
16
|
if (typeof window.CWI !== 'object') {
|
|
17
17
|
throw new Error('The window.CWI interface does not appear to be bound to the window object.')
|
|
18
18
|
}
|
|
19
|
-
this.CWI = window.CWI as
|
|
19
|
+
this.CWI = window.CWI as WalletInterface // Binding CWI to prevent changes
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
async createAction(args: { description: DescriptionString5to50Bytes, inputs?: Array<{ tx?: BEEF, outpoint: OutpointString, unlockingScript?: HexString, unlockingScriptLength?: PositiveInteger, inputDescription: DescriptionString5to50Bytes, sequenceNumber?: PositiveIntegerOrZero }>, outputs?: Array<{ lockingScript: HexString, satoshis: SatoshiValue, outputDescription: DescriptionString5to50Bytes, basket?: BasketStringUnder300Bytes, customInstructions?: string, tags?: OutputTagStringUnder300Bytes[] }>, lockTime?: PositiveIntegerOrZero, version?: PositiveIntegerOrZero, labels?: LabelStringUnder300Bytes[], options?: { signAndProcess?: BooleanDefaultTrue, acceptDelayedBroadcast?: BooleanDefaultTrue, trustSelf?: 'known', knownTxids?: TXIDHexString[], returnTXIDOnly?: BooleanDefaultFalse, noSend?: BooleanDefaultFalse, noSendChange?: OutpointString[], sendWith?: TXIDHexString[] } }, originator?: OriginatorDomainNameStringUnder250Bytes): Promise<{ txid?: TXIDHexString, tx?: BEEF, noSendChange?: OutpointString[], sendWithResults?: Array<{ txid: TXIDHexString, status: 'unproven' | 'sending' | 'failed' }>, signableTransaction?: { tx: BEEF, reference: Base64String } }> {
|