Skip to content

Commit 9b3f912

Browse files
committed
feat: replace bs58 dep with ethers
1 parent 4df408f commit 9b3f912

File tree

8 files changed

+786
-901
lines changed

8 files changed

+786
-901
lines changed

local-tests/tests/wrapped-keys/testGenerateSolanaWrappedKey.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { log } from '@lit-protocol/misc';
22
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
33
import { api } from '@lit-protocol/wrapped-keys';
44
import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs';
5-
import nacl from 'tweetnacl';
6-
import bs58 from 'bs58';
75
import { Keypair } from '@solana/web3.js';
6+
import { ethers } from 'ethers';
7+
import nacl from 'tweetnacl';
88

99
const { generatePrivateKey, signMessageWithEncryptedKey, exportPrivateKey } =
1010
api;
@@ -68,8 +68,8 @@ export const testGenerateSolanaWrappedKey = async (
6868

6969
const signatureIsValidForPublicKey = nacl.sign.detached.verify(
7070
Buffer.from(messageToSign),
71-
bs58.decode(signature),
72-
bs58.decode(generatedPublicKey)
71+
ethers.utils.base58.decode(signature),
72+
ethers.utils.base58.decode(generatedPublicKey)
7373
);
7474

7575
if (!signatureIsValidForPublicKey)

local-tests/tests/wrapped-keys/testSignMessageWithSolanaEncryptedKey.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { log } from '@lit-protocol/misc';
22
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
33
import { api } from '@lit-protocol/wrapped-keys';
44
import { Keypair } from '@solana/web3.js';
5-
import bs58 from 'bs58';
5+
import { ethers } from 'ethers';
66
import nacl from 'tweetnacl';
77
import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs';
88

@@ -68,7 +68,7 @@ export const testSignMessageWithSolanaEncryptedKey = async (
6868

6969
const signatureIsValidForPublicKey = nacl.sign.detached.verify(
7070
Buffer.from(messageToSign),
71-
bs58.decode(signature),
71+
ethers.utils.base58.decode(signature),
7272
solanaKeypair.publicKey.toBuffer()
7373
);
7474

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
"@dotenvx/dotenvx": "^1.6.4",
4343
"@ethersproject/abi": "^5.7.0",
4444
"@ethersproject/providers": "^5.7.2",
45-
"@lit-protocol/contracts": "^0.0.63",
4645
"@lit-protocol/accs-schemas": "^0.0.12",
46+
"@lit-protocol/contracts": "^0.0.63",
4747
"@metamask/eth-sig-util": "5.0.2",
4848
"@mysten/sui.js": "^0.37.1",
4949
"@openagenda/verror": "^3.1.4",
@@ -57,7 +57,6 @@
5757
"ajv": "^8.12.0",
5858
"base64url": "^3.0.1",
5959
"bech32": "^2.0.0",
60-
"bs58": "^5.0.0",
6160
"cbor-web": "^9.0.2",
6261
"cross-fetch": "3.1.8",
6362
"date-and-time": "^2.4.1",
@@ -98,11 +97,11 @@
9897
"buffer": "^6.0.3",
9998
"chalk": "^5.3.0",
10099
"cypress": "11.0.1",
101-
"esbuild-node-externals": "^1.14.0",
102100
"cypress-metamask": "^1.0.5-development",
103101
"cypress-metamask-v2": "^1.7.2",
104102
"esbuild": "^0.17.3",
105103
"esbuild-node-builtins": "^0.1.0",
104+
"esbuild-node-externals": "^1.14.0",
106105
"esbuild-plugin-tsc": "^0.4.0",
107106
"eslint": "8.48.0",
108107
"eslint-config-next": "12.2.3",

packages/contracts-sdk/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"directory": "../../dist/packages/contracts-sdk"
1919
},
2020
"peerDependencies": {
21-
"bs58": "^5.0.0",
2221
"date-and-time": "^2.4.1",
2322
"multiformats": "^9.7.1"
2423
},

packages/contracts-sdk/src/lib/contracts-sdk.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
MintWithAuthParams,
1515
MintWithAuthResponse,
1616
} from '@lit-protocol/types';
17-
import bs58 from 'bs58';
1817
import { BigNumberish, BytesLike, ContractReceipt, ethers } from 'ethers';
1918
import { decToHex, hexToDec, intToIP } from './hex2dec';
2019

@@ -1708,7 +1707,7 @@ https://developer.litprotocol.com/v3/sdk/wallets/auth-methods/#auth-method-scope
17081707
* @returns {string}
17091708
*/
17101709
getBytesFromMultihash: (multihash: string) => {
1711-
const decoded = bs58.decode(multihash);
1710+
const decoded = ethers.utils.base58.decode(multihash);
17121711

17131712
return `0x${Buffer.from(decoded).toString('hex')}`;
17141713
},
@@ -1726,7 +1725,9 @@ https://developer.litprotocol.com/v3/sdk/wallets/auth-methods/#auth-method-scope
17261725
const digestSize = parseInt(text.slice(2, 4), 16);
17271726
const digest = text.slice(4, 4 + digestSize * 2);
17281727

1729-
const multihash = bs58.encode(Buffer.from(`1220${digest}`, 'hex'));
1728+
const multihash = ethers.utils.base58.encode(
1729+
Buffer.from(`1220${digest}`, 'hex')
1730+
);
17301731

17311732
return multihash;
17321733
},

packages/misc/src/lib/addresses.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
} from '@lit-protocol/constants';
66
import { TokenInfo } from '@lit-protocol/types';
77
import { bech32 } from 'bech32';
8-
import bs58 from 'bs58';
98
import { createHash } from 'crypto';
109
import { Contract, ethers } from 'ethers';
1110
import { computeAddress } from 'ethers/lib/utils';
@@ -112,7 +111,7 @@ function deriveBitcoinAddress(ethPubKey: string): string {
112111
const binaryBitcoinAddress = Buffer.concat([versionedPayload, checksum]);
113112

114113
// Encode the result with Base58 to get the final Bitcoin address and return it
115-
return bs58.encode(binaryBitcoinAddress);
114+
return ethers.utils.base58.encode(binaryBitcoinAddress);
116115
}
117116

118117
/**

packages/pkp-sui/src/lib/TransactionBlockData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { hashTypedData } from './hash';
5-
import bs58 from 'bs58';
5+
import { ethers } from 'ethers';
66

77
/**
88
* Generate transaction digest.
@@ -12,5 +12,5 @@ import bs58 from 'bs58';
1212
*/
1313
export function getDigestFromBytes(bytes: Uint8Array) {
1414
const hash = hashTypedData('TransactionData', bytes);
15-
return bs58.encode(hash);
15+
return ethers.utils.base58.encode(hash);
1616
}

0 commit comments

Comments
 (0)