@tetherto/wdk-wallet 1.0.0-beta.14 → 1.0.0-beta.16

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/index.js CHANGED
@@ -32,6 +32,12 @@ export {
32
32
 
33
33
  export { IWalletAccount } from './src/wallet-account.js'
34
34
 
35
- export { NotImplementedError, SignerError } from './src/errors.js'
35
+ export {
36
+ NotImplementedError,
37
+ SignerError,
38
+ UnsupportedOperationError,
39
+ ValueError,
40
+ NoSuchElementError
41
+ } from './src/errors.js'
36
42
 
37
43
  export { ISigner } from './src/signer.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tetherto/wdk-wallet",
3
- "version": "1.0.0-beta.14",
3
+ "version": "1.0.0-beta.16",
4
4
  "description": "A simple package to manage BIP-32 wallets.",
5
5
  "keywords": [
6
6
  "wdk",
@@ -43,6 +43,10 @@
43
43
  "types": "./types/src/protocols/index.d.ts",
44
44
  "default": "./src/protocols/index.js"
45
45
  },
46
+ "./multisig": {
47
+ "types": "./types/src/multisig/index.d.ts",
48
+ "default": "./src/multisig/index.js"
49
+ },
46
50
  "./package": {
47
51
  "default": "./package.json"
48
52
  }
package/src/errors.js CHANGED
@@ -38,3 +38,44 @@ export class SignerError extends Error {
38
38
  this.name = 'SignerError'
39
39
  }
40
40
  }
41
+
42
+ export class UnsupportedOperationError extends Error {
43
+ /**
44
+ * Create a new unsupported operation error. Thrown by an optional operation
45
+ * that the concrete implementation deliberately does not support.
46
+ *
47
+ * @param {string} operation - The name of the operation that is not supported.
48
+ */
49
+ constructor (operation) {
50
+ super(`Operation '${operation}' is not supported by this protocol.`)
51
+
52
+ this.name = 'UnsupportedOperationError'
53
+ }
54
+ }
55
+
56
+ export class ValueError extends Error {
57
+ /**
58
+ * Create a new value error. Thrown when an argument fails validation.
59
+ *
60
+ * @param {string} message - The error's message.
61
+ */
62
+ constructor (message) {
63
+ super(message)
64
+
65
+ this.name = 'ValueError'
66
+ }
67
+ }
68
+
69
+ export class NoSuchElementError extends Error {
70
+ /**
71
+ * Create a new no such element error. Thrown when a lookup finds no element for
72
+ * the given identifier.
73
+ *
74
+ * @param {string} message - The error's message.
75
+ */
76
+ constructor (message) {
77
+ super(message)
78
+
79
+ this.name = 'NoSuchElementError'
80
+ }
81
+ }
@@ -0,0 +1,30 @@
1
+ // Copyright 2024 Tether Operations Limited
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ 'use strict'
15
+
16
+ /** @typedef {import('./wallet-account-read-only-multisig.js').MultisigInfo} MultisigInfo */
17
+ /** @typedef {import('./wallet-account-read-only-multisig.js').MultisigProposal} MultisigProposal */
18
+ /** @typedef {import('./wallet-account-read-only-multisig.js').MultisigMessageProposal} MultisigMessageProposal */
19
+ /** @typedef {import('../wallet-account.js').KeyPair} KeyPair */
20
+
21
+ /** @typedef {import('./wallet-account-multisig.js').MultisigTransactionOptions} MultisigTransactionOptions */
22
+ /** @typedef {import('./wallet-account-multisig.js').MultisigAutoExecuteResult} MultisigAutoExecuteResult */
23
+ /** @typedef {import('./wallet-account-multisig.js').MultisigSignature} MultisigSignature */
24
+ /** @typedef {import('./multisig-owner-management.js').MultisigOptions} MultisigOptions */
25
+
26
+ export { IWalletAccountReadOnlyMultisig } from './wallet-account-read-only-multisig.js'
27
+
28
+ export { IWalletAccountMultisig } from './wallet-account-multisig.js'
29
+
30
+ export { IMultisigOwnerManagement } from './multisig-owner-management.js'
@@ -0,0 +1,77 @@
1
+ // Copyright 2024 Tether Operations Limited
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ 'use strict'
15
+
16
+ import { NotImplementedError } from '../errors.js'
17
+
18
+ /** @typedef {import('./wallet-account-read-only-multisig.js').MultisigProposal} MultisigProposal */
19
+
20
+ /**
21
+ * @typedef {Object} MultisigOptions
22
+ * @property {number} threshold - The new amount of approvals required to execute a transaction.
23
+ */
24
+
25
+ /**
26
+ * Adds owner management features to a multisig wallet.
27
+ *
28
+ * @interface
29
+ */
30
+ export class IMultisigOwnerManagement {
31
+ /**
32
+ * Proposes adding a new owner to the multisig wallet account.
33
+ *
34
+ * @param {string} owner - The owner's address.
35
+ * @param {MultisigOptions} [options] - The multisig options.
36
+ * @returns {Promise<MultisigProposal>} The multisig proposal.
37
+ * @throws {Error} If the account is not an owner of the multisig wallet.
38
+ */
39
+ async addOwner (owner, options) {
40
+ throw new NotImplementedError('addOwner(owner, options)')
41
+ }
42
+
43
+ /**
44
+ * Proposes removing an owner from the multisig wallet account.
45
+ *
46
+ * @param {string} owner - The owner's address.
47
+ * @param {MultisigOptions} [options] - The multisig options.
48
+ * @returns {Promise<MultisigProposal>} The multisig proposal.
49
+ * @throws {Error} If the account is not an owner of the multisig wallet.
50
+ */
51
+ async removeOwner (owner, options) {
52
+ throw new NotImplementedError('removeOwner(owner, options)')
53
+ }
54
+
55
+ /**
56
+ * Proposes replacing an owner with a different one.
57
+ *
58
+ * @param {string} oldOwner - The old owner.
59
+ * @param {string} newOwner - The new owner.
60
+ * @returns {Promise<MultisigProposal>} The multisig proposal.
61
+ * @throws {Error} If the account is not an owner of the multisig wallet.
62
+ */
63
+ async swapOwner (oldOwner, newOwner) {
64
+ throw new NotImplementedError('swapOwner(oldOwner, newOwner)')
65
+ }
66
+
67
+ /**
68
+ * Proposes changing the signature threshold.
69
+ *
70
+ * @param {number} newThreshold - The new threshold.
71
+ * @returns {Promise<MultisigProposal>} The multisig proposal.
72
+ * @throws {Error} If the account is not an owner of the multisig wallet.
73
+ */
74
+ async changeThreshold (newThreshold) {
75
+ throw new NotImplementedError('changeThreshold(newThreshold)')
76
+ }
77
+ }
@@ -0,0 +1,155 @@
1
+ // Copyright 2024 Tether Operations Limited
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ 'use strict'
15
+
16
+ import { IWalletAccountReadOnlyMultisig } from './wallet-account-read-only-multisig.js'
17
+
18
+ import { NotImplementedError } from '../errors.js'
19
+
20
+ /** @typedef {import('../wallet-account-read-only.js').Transaction} Transaction */
21
+ /** @typedef {import('../wallet-account-read-only.js').TransactionResult} TransactionResult */
22
+
23
+ /** @typedef {import('../wallet-account.js').KeyPair} KeyPair */
24
+
25
+ /** @typedef {import('./wallet-account-read-only-multisig.js').MultisigProposal} MultisigProposal */
26
+ /** @typedef {import('./wallet-account-read-only-multisig.js').MultisigMessageProposal} MultisigMessageProposal */
27
+
28
+ /** @typedef {import('../errors.js').NoSuchElementError} NoSuchElementError */
29
+ /** @typedef {import('../errors.js').ValueError} ValueError */
30
+
31
+ /**
32
+ * @typedef {Object} MultisigTransactionOptions
33
+ * @property {boolean} [autoExecute] - If true, automatically executes the transaction when the approval threshold is met (only takes effect if this signer's approval is the last one required).
34
+ */
35
+
36
+ /**
37
+ * @typedef {Object} MultisigAutoExecuteResult
38
+ * @property {TransactionResult} [transaction] - If auto execute is set to true and the method call triggers the execution of the proposal, this field is set to the corresponding transaction's result (i.e., hash and fee).
39
+ */
40
+
41
+ /**
42
+ * @typedef {Object} MultisigSignature
43
+ * @property {string} signature - The caller's signature.
44
+ */
45
+
46
+ /** @interface */
47
+ export class IWalletAccountMultisig extends IWalletAccountReadOnlyMultisig {
48
+ /**
49
+ * The derivation path's index of this account.
50
+ *
51
+ * @type {number}
52
+ */
53
+ get index () {
54
+ throw new NotImplementedError('index')
55
+ }
56
+
57
+ /**
58
+ * The derivation path of this account (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)).
59
+ *
60
+ * @type {string}
61
+ */
62
+ get path () {
63
+ throw new NotImplementedError('path')
64
+ }
65
+
66
+ /**
67
+ * The key pair of this account.
68
+ *
69
+ * @type {KeyPair}
70
+ */
71
+ get keyPair () {
72
+ throw new NotImplementedError('keyPair')
73
+ }
74
+
75
+ /**
76
+ * Returns the signer's address.
77
+ *
78
+ * @returns {Promise<string>} The signer's address.
79
+ */
80
+ async getSignerAddress () {
81
+ throw new NotImplementedError('getSignerAddress()')
82
+ }
83
+
84
+ /**
85
+ * Proposes sending a transaction for the other owners to approve. Does not execute on-chain:
86
+ * the returned proposal must be approved up to the threshold and then executed via
87
+ * {@link executeProposal}.
88
+ *
89
+ * @param {Transaction} tx - The transaction.
90
+ * @param {MultisigTransactionOptions} [transactionOptions] - The multisig transaction's options.
91
+ * @returns {Promise<MultisigProposal & MultisigAutoExecuteResult>} The created proposal; its `status` is `'executed'` when `autoExecute` ran to completion, otherwise `'pending'`.
92
+ * @throws {Error} If the account is not an owner of the multisig wallet.
93
+ */
94
+ async propose (tx, transactionOptions) {
95
+ throw new NotImplementedError('propose(tx, transactionOptions)')
96
+ }
97
+
98
+ /**
99
+ * Proposes signing a message.
100
+ *
101
+ * @param {string} message - The message to sign.
102
+ * @returns {Promise<MultisigMessageProposal & MultisigSignature>} The multisig message proposal.
103
+ * @throws {Error} If the account is not an owner of the multisig wallet.
104
+ */
105
+ async proposeMessage (message) {
106
+ throw new NotImplementedError('proposeMessage(message)')
107
+ }
108
+
109
+ /**
110
+ * Approves an existing message proposal.
111
+ *
112
+ * @param {string} messageId - The message's hash.
113
+ * @returns {Promise<MultisigMessageProposal & MultisigSignature>} The multisig message proposal.
114
+ * @throws {Error} If the account is not an owner of the multisig wallet.
115
+ * @throws {NoSuchElementError} If no message exists for the given id.
116
+ */
117
+ async approveMessageProposal (messageId) {
118
+ throw new NotImplementedError('approveMessageProposal(messageId)')
119
+ }
120
+
121
+ /**
122
+ * Approves a pending proposal.
123
+ *
124
+ * @param {string} proposalId - The proposal's id.
125
+ * @returns {Promise<MultisigProposal & MultisigAutoExecuteResult>} The multisig proposal.
126
+ * @throws {Error} If the account is not an owner of the multisig wallet.
127
+ * @throws {NoSuchElementError} If no proposal exists for the given id.
128
+ */
129
+ async approveProposal (proposalId) {
130
+ throw new NotImplementedError('approveProposal(proposalId)')
131
+ }
132
+
133
+ /**
134
+ * Rejects a pending proposal.
135
+ *
136
+ * @param {string} proposalId - The proposal's id.
137
+ * @returns {Promise<MultisigProposal>} The multisig proposal.
138
+ * @throws {NoSuchElementError} If no proposal exists for the given id.
139
+ */
140
+ async rejectProposal (proposalId) {
141
+ throw new NotImplementedError('rejectProposal(proposalId)')
142
+ }
143
+
144
+ /**
145
+ * Submits an approved proposal for on-chain execution.
146
+ *
147
+ * @param {string} proposalId - The proposal's id.
148
+ * @returns {Promise<TransactionResult>} The on-chain transaction's result.
149
+ * @throws {NoSuchElementError} If no proposal exists for the given id.
150
+ * @throws {ValueError} If the proposal has not reached the approval threshold.
151
+ */
152
+ async executeProposal (proposalId) {
153
+ throw new NotImplementedError('executeProposal(proposalId)')
154
+ }
155
+ }
@@ -0,0 +1,112 @@
1
+ // Copyright 2024 Tether Operations Limited
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ 'use strict'
15
+
16
+ import { IWalletAccountReadOnlySimple } from '../wallet-account-read-only-simple.js'
17
+
18
+ import { NotImplementedError } from '../errors.js'
19
+
20
+ /** @typedef {import('../errors.js').NoSuchElementError} NoSuchElementError */
21
+
22
+ /** @typedef {import('../wallet-account-read-only.js').TransactionResult} TransactionResult */
23
+
24
+ /**
25
+ * @typedef {Object} MultisigInfo
26
+ * @property {string} address - The multisig wallet account address.
27
+ * @property {string[]} owners - The owners of the multisig wallet account.
28
+ * @property {number} threshold - The minimum amount of signatures to execute a transaction.
29
+ */
30
+
31
+ /**
32
+ *
33
+ * @typedef {Object} MultisigProposal
34
+ * @property {string} proposalId - The proposal's id.
35
+ * @property {number} confirmations - The current number of confirmations.
36
+ * @property {number} threshold - The minimum amount of confirmations to execute the transaction.
37
+ * @property {'pending' | 'executed'} status - The proposal's lifecycle state: `'pending'` while it still awaits confirmations or on-chain execution, `'executed'` once it has been executed on-chain.
38
+ */
39
+
40
+ /**
41
+ * @typedef {Object} MultisigMessageProposal
42
+ * @property {string} messageId - The message's hash.
43
+ * @property {string} message - The original message.
44
+ * @property {number} confirmations - The current number of confirmations.
45
+ * @property {number} threshold - The minimum amount of confirmations to sign the message.
46
+ * @property {string | null} combinedSignature - The final combined signature when the threshold is met.
47
+ */
48
+
49
+ /** @interface */
50
+ export class IWalletAccountReadOnlyMultisig extends IWalletAccountReadOnlySimple {
51
+ /**
52
+ * Returns the multisig wallet account info.
53
+ *
54
+ * @returns {Promise<MultisigInfo>} The info.
55
+ */
56
+ async getMultisigInfo () {
57
+ throw new NotImplementedError('getMultisigInfo()')
58
+ }
59
+
60
+ /**
61
+ * Returns a list of proposals by their identifiers.
62
+ *
63
+ * @param {string[]} proposalIds - The list of proposal identifiers.
64
+ * @returns {Promise<Record<string, MultisigProposal | null>>} For each proposal id, the proposal details or
65
+ * null if the proposal has not been found.
66
+ */
67
+ async getProposals (proposalIds) {
68
+ throw new NotImplementedError('getProposals(proposalIds)')
69
+ }
70
+
71
+ /**
72
+ * Returns a proposal by its identifier.
73
+ *
74
+ * @param {string} proposalId - The proposal's identifier.
75
+ * @returns {Promise<MultisigProposal | null>} The proposal details, or null if it has not been found.
76
+ */
77
+ async getProposal (proposalId) {
78
+ throw new NotImplementedError('getProposal(proposalId)')
79
+ }
80
+
81
+ /**
82
+ * Returns a list of message proposals by their hashes.
83
+ *
84
+ * @param {string[]} messageIds - The list of message hashes
85
+ * @returns {Promise<Record<string, MultisigMessageProposal | null>>} For each message hash, the message details or
86
+ * null if the message has not been found.
87
+ */
88
+ async getMessageProposals (messageIds) {
89
+ throw new NotImplementedError('getMessageProposals(messageIds)')
90
+ }
91
+
92
+ /**
93
+ * Returns a message proposal by its identifier.
94
+ *
95
+ * @param {string} messageId - The message's hash.
96
+ * @returns {Promise<MultisigMessageProposal | null>} The message details, or null if it has not been found.
97
+ */
98
+ async getMessageProposal (messageId) {
99
+ throw new NotImplementedError('getMessageProposal(messageId)')
100
+ }
101
+
102
+ /**
103
+ * Quotes the on-chain cost of executing a pending proposal.
104
+ *
105
+ * @param {string} proposalId - The proposal's id.
106
+ * @returns {Promise<Omit<TransactionResult, 'hash'>>} The execution cost estimate.
107
+ * @throws {NoSuchElementError} If no proposal exists for the given id.
108
+ */
109
+ async quoteExecuteProposal (proposalId) {
110
+ throw new NotImplementedError('quoteExecuteProposal(proposalId)')
111
+ }
112
+ }
@@ -68,6 +68,25 @@
68
68
  /** @typedef {import('./swidge-protocol.js').SwidgeSupportedToken} SwidgeSupportedToken */
69
69
  /** @typedef {import('./swidge-protocol.js').SwidgeSupportedTokensOptions} SwidgeSupportedTokensOptions */
70
70
 
71
+ /** @typedef {import('./sda-protocol.js').Blockchain} Blockchain */
72
+ /** @typedef {import('./sda-protocol.js').SdaToken} SdaToken */
73
+ /** @typedef {import('./sda-protocol.js').SdaDepositAddressLimits} SdaDepositAddressLimits */
74
+ /** @typedef {import('./sda-protocol.js').SdaRoutesOptions} SdaRoutesOptions */
75
+ /** @typedef {import('./sda-protocol.js').SdaRoute} SdaRoute */
76
+ /** @typedef {import('./sda-protocol.js').SdaDepositOptions} SdaDepositOptions */
77
+ /** @typedef {import('./sda-protocol.js').SdaFeeType} SdaFeeType */
78
+ /** @typedef {import('./sda-protocol.js').SdaFee} SdaFee */
79
+ /** @typedef {import('./sda-protocol.js').SdaDepositQuote} SdaDepositQuote */
80
+ /** @typedef {import('./sda-protocol.js').SdaCreateDepositAddressOptions} SdaCreateDepositAddressOptions */
81
+ /** @typedef {import('./sda-protocol.js').SdaDepositAddress} SdaDepositAddress */
82
+ /** @typedef {import('./sda-protocol.js').SdaTransferStatus} SdaTransferStatus */
83
+ /** @typedef {import('./sda-protocol.js').SdaTransfer} SdaTransfer */
84
+ /** @typedef {import('./sda-protocol.js').SdaTransfersOptions} SdaTransfersOptions */
85
+ /** @typedef {import('./sda-protocol.js').SdaRecoverById} SdaRecoverById */
86
+ /** @typedef {import('./sda-protocol.js').SdaRecoverByAddress} SdaRecoverByAddress */
87
+ /** @typedef {import('./sda-protocol.js').SdaRecoveryOptions} SdaRecoveryOptions */
88
+ /** @typedef {import('./sda-protocol.js').SdaRecoveryResult} SdaRecoveryResult */
89
+
71
90
  export { default as SwapProtocol, ISwapProtocol } from './swap-protocol.js'
72
91
 
73
92
  export { default as BridgeProtocol, IBridgeProtocol } from './bridge-protocol.js'
@@ -77,3 +96,5 @@ export { default as LendingProtocol, ILendingProtocol } from './lending-protocol
77
96
  export { default as FiatProtocol, IFiatProtocol } from './fiat-protocol.js'
78
97
 
79
98
  export { default as SwidgeProtocol, ISwidgeProtocol } from './swidge-protocol.js'
99
+
100
+ export { default as SdaProtocol, ISdaProtocol } from './sda-protocol.js'