@bsv/wallet-toolbox 1.2.28 → 1.2.30
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/out/src/WalletPermissionsManager.d.ts.map +1 -1
- package/out/src/WalletPermissionsManager.js +2 -2
- package/out/src/WalletPermissionsManager.js.map +1 -1
- package/out/src/__tests/WalletPermissionsManager.encryption.test.js +8 -7
- package/out/src/__tests/WalletPermissionsManager.encryption.test.js.map +1 -1
- package/out/src/__tests/WalletPermissionsManager.fixtures.d.ts +2 -0
- package/out/src/__tests/WalletPermissionsManager.fixtures.d.ts.map +1 -1
- package/out/src/__tests/WalletPermissionsManager.fixtures.js +5 -0
- package/out/src/__tests/WalletPermissionsManager.fixtures.js.map +1 -1
- package/out/tsconfig.all.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/WalletPermissionsManager.ts +5 -5
- package/src/__tests/WalletPermissionsManager.encryption.test.ts +8 -7
- package/src/__tests/WalletPermissionsManager.fixtures.ts +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsv/wallet-toolbox",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.30",
|
|
4
4
|
"description": "BRC100 conforming wallet, wallet storage and wallet signer components",
|
|
5
5
|
"main": "./out/src/index.js",
|
|
6
6
|
"types": "./out/src/index.d.ts",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://github.com/bitcoin-sv/wallet-toolbox#readme",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@bsv/auth-express-middleware": "^1.
|
|
34
|
-
"@bsv/payment-express-middleware": "^1.0.
|
|
35
|
-
"@bsv/sdk": "^1.4.
|
|
33
|
+
"@bsv/auth-express-middleware": "^1.1.2",
|
|
34
|
+
"@bsv/payment-express-middleware": "^1.0.4",
|
|
35
|
+
"@bsv/sdk": "^1.4.12",
|
|
36
36
|
"express": "^4.21.2",
|
|
37
37
|
"knex": "^3.1.0",
|
|
38
38
|
"mysql2": "^3.12.0",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WalletInterface, Utils, PushDrop, LockingScript, Transaction, WalletProtocol } from '@bsv/sdk'
|
|
1
|
+
import { WalletInterface, Utils, PushDrop, LockingScript, Transaction, WalletProtocol, Base64String } from '@bsv/sdk'
|
|
2
2
|
import { validateCreateActionArgs } from './sdk'
|
|
3
3
|
|
|
4
4
|
////// TODO: ADD SUPPORT FOR ADMIN COUNTERPARTIES BASED ON WALLET STORAGE
|
|
@@ -939,7 +939,7 @@ export class WalletPermissionsManager implements WalletInterface {
|
|
|
939
939
|
* @param plaintext The metadata to encrypt if configured to do so
|
|
940
940
|
* @returns The encrypted metadata, or the original value if encryption was disabled.
|
|
941
941
|
*/
|
|
942
|
-
private async maybeEncryptMetadata(plaintext: string): Promise<
|
|
942
|
+
private async maybeEncryptMetadata(plaintext: string): Promise<Base64String> {
|
|
943
943
|
if (!this.config.encryptWalletMetadata) {
|
|
944
944
|
return plaintext
|
|
945
945
|
}
|
|
@@ -951,7 +951,7 @@ export class WalletPermissionsManager implements WalletInterface {
|
|
|
951
951
|
},
|
|
952
952
|
this.adminOriginator
|
|
953
953
|
)
|
|
954
|
-
return Utils.
|
|
954
|
+
return Utils.toBase64(ciphertext)
|
|
955
955
|
}
|
|
956
956
|
|
|
957
957
|
/**
|
|
@@ -959,11 +959,11 @@ export class WalletPermissionsManager implements WalletInterface {
|
|
|
959
959
|
* @param ciphertext The metadata to attempt decryption for.
|
|
960
960
|
* @returns The decrypted metadata. If decryption fails, returns the original value instead.
|
|
961
961
|
*/
|
|
962
|
-
private async maybeDecryptMetadata(ciphertext:
|
|
962
|
+
private async maybeDecryptMetadata(ciphertext: Base64String): Promise<string> {
|
|
963
963
|
try {
|
|
964
964
|
const { plaintext } = await this.underlying.decrypt(
|
|
965
965
|
{
|
|
966
|
-
ciphertext: Utils.toArray(ciphertext, '
|
|
966
|
+
ciphertext: Utils.toArray(ciphertext, 'base64'),
|
|
967
967
|
protocolID: WalletPermissionsManager.METADATA_ENCRYPTION_PROTOCOL,
|
|
968
968
|
keyID: '1'
|
|
969
969
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { mockUnderlyingWallet, MockedBSV_SDK } from './WalletPermissionsManager.fixtures'
|
|
2
2
|
import { WalletPermissionsManager } from '../WalletPermissionsManager'
|
|
3
3
|
import { jest } from '@jest/globals'
|
|
4
|
+
import { Utils } from '@bsv/sdk'
|
|
4
5
|
|
|
5
6
|
jest.mock('@bsv/sdk', () => MockedBSV_SDK)
|
|
6
7
|
|
|
@@ -62,7 +63,7 @@ describe('WalletPermissionsManager - Metadata Encryption & Decryption', () => {
|
|
|
62
63
|
plaintext: [72, 105] // 'Hi'
|
|
63
64
|
})
|
|
64
65
|
|
|
65
|
-
const ciphertext = 'random-string-representing-ciphertext'
|
|
66
|
+
const ciphertext = Utils.toBase64(Utils.toArray('random-string-representing-ciphertext'))
|
|
66
67
|
const result = await manager['maybeDecryptMetadata'](ciphertext)
|
|
67
68
|
|
|
68
69
|
// We expect underlying.decrypt() to have been called
|
|
@@ -153,19 +154,19 @@ describe('WalletPermissionsManager - Metadata Encryption & Decryption', () => {
|
|
|
153
154
|
totalActions: 1,
|
|
154
155
|
actions: [
|
|
155
156
|
{
|
|
156
|
-
description: 'fake-encrypted-string-for-description',
|
|
157
|
+
description: Utils.toBase64(Utils.toArray('fake-encrypted-string-for-description')),
|
|
157
158
|
inputs: [
|
|
158
159
|
{
|
|
159
160
|
outpoint: 'txid1.0',
|
|
160
|
-
inputDescription: 'fake-encrypted-string-for-inputDesc'
|
|
161
|
+
inputDescription: Utils.toBase64(Utils.toArray('fake-encrypted-string-for-inputDesc'))
|
|
161
162
|
}
|
|
162
163
|
],
|
|
163
164
|
outputs: [
|
|
164
165
|
{
|
|
165
166
|
lockingScript: 'OP_RETURN 1234',
|
|
166
167
|
satoshis: 500,
|
|
167
|
-
outputDescription: 'fake-encrypted-string-for-outputDesc',
|
|
168
|
-
customInstructions: 'fake-encrypted-string-for-customInstr'
|
|
168
|
+
outputDescription: Utils.toBase64(Utils.toArray('fake-encrypted-string-for-outputDesc')),
|
|
169
|
+
customInstructions: Utils.toBase64(Utils.toArray('fake-encrypted-string-for-customInstr'))
|
|
169
170
|
}
|
|
170
171
|
]
|
|
171
172
|
}
|
|
@@ -268,7 +269,7 @@ describe('WalletPermissionsManager - Metadata Encryption & Decryption', () => {
|
|
|
268
269
|
// To simulate, we make decryption pass through.
|
|
269
270
|
underlying.decrypt.mockImplementation(x => x)
|
|
270
271
|
const listResult = await (manager as any).listActions({}, 'nonadmin.com')
|
|
271
|
-
expect(underlying.decrypt).toHaveBeenCalledTimes(
|
|
272
|
+
expect(underlying.decrypt).toHaveBeenCalledTimes(3)
|
|
272
273
|
|
|
273
274
|
// Confirm the returned data is the same as originally provided (plaintext)
|
|
274
275
|
const [first] = listResult.actions
|
|
@@ -297,7 +298,7 @@ describe('WalletPermissionsManager - Metadata Encryption & Decryption', () => {
|
|
|
297
298
|
satoshis: 999,
|
|
298
299
|
lockingScript: 'OP_RETURN something',
|
|
299
300
|
basket: 'some-basket',
|
|
300
|
-
customInstructions: 'fake-encrypted-instructions-string'
|
|
301
|
+
customInstructions: Utils.toBase64(Utils.toArray('fake-encrypted-instructions-string'))
|
|
301
302
|
}
|
|
302
303
|
]
|
|
303
304
|
})
|
|
@@ -153,6 +153,12 @@ export const MockUtils = {
|
|
|
153
153
|
toUTF8: (arr: number[]) => {
|
|
154
154
|
// Converts an array of numbers to a UTF-8 string.
|
|
155
155
|
return String.fromCharCode(...arr)
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
toBase64: (arr: number[]) => {
|
|
159
|
+
// Converts an array of numbers to a Base64 string.
|
|
160
|
+
const binaryStr = String.fromCharCode(...arr)
|
|
161
|
+
return btoa(binaryStr)
|
|
156
162
|
}
|
|
157
163
|
}
|
|
158
164
|
|