Skip to content

Commit 7e1e778

Browse files
committed
Merge branch 'refs/heads/staging/v7' into feature/lit-3796-js-sdk-research-to-use-zod
# Conflicts: # yarn.lock
2 parents 093716f + 0d5fa42 commit 7e1e778

File tree

16 files changed

+119
-82
lines changed

16 files changed

+119
-82
lines changed

local-tests/tests/testDelegatingCapacityCreditsNFTToAnotherPkpToExecuteJs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const testDelegatingCapacityCreditsNFTToAnotherPkpToExecuteJs = async (
3939

4040
// As a dApp owner, create a capacity delegation authSig for Bob's PKP wallet
4141
const capacityDelegationAuthSig = await alice.createCapacityDelegationAuthSig(
42-
[bob.pkp.ethAddress]
42+
[bob.authMethodOwnedPkp.ethAddress]
4343
);
4444

4545
// As a dApp owner, delegate the capacity credits NFT to Bob

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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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",

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
@@ -17,7 +17,6 @@ import {
1717
MintWithAuthParams,
1818
MintWithAuthResponse,
1919
} from '@lit-protocol/types';
20-
import bs58 from 'bs58';
2120
import { BigNumberish, BytesLike, ContractReceipt, ethers } from 'ethers';
2221
import { decToHex, hexToDec, intToIP } from './hex2dec';
2322

@@ -1717,7 +1716,7 @@ https://developer.litprotocol.com/v3/sdk/wallets/auth-methods/#auth-method-scope
17171716
* @returns {string}
17181717
*/
17191718
getBytesFromMultihash: (multihash: string) => {
1720-
const decoded = bs58.decode(multihash);
1719+
const decoded = ethers.utils.base58.decode(multihash);
17211720

17221721
return `0x${Buffer.from(decoded).toString('hex')}`;
17231722
},
@@ -1735,7 +1734,9 @@ https://developer.litprotocol.com/v3/sdk/wallets/auth-methods/#auth-method-scope
17351734
const digestSize = parseInt(text.slice(2, 4), 16);
17361735
const digest = text.slice(4, 4 + digestSize * 2);
17371736

1738-
const multihash = bs58.encode(Buffer.from(`1220${digest}`, 'hex'));
1737+
const multihash = ethers.utils.base58.encode(
1738+
Buffer.from(`1220${digest}`, 'hex')
1739+
);
17391740

17401741
return multihash;
17411742
},

packages/core/src/lib/lit-core.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
LIT_CURVE,
2222
LIT_CURVE_VALUES,
2323
LIT_ENDPOINT,
24+
LIT_ERROR,
2425
LIT_ERROR_CODE,
2526
LIT_NETWORK,
2627
LIT_NETWORKS,
@@ -74,6 +75,7 @@ import {
7475
} from '@lit-protocol/types';
7576

7677
import { composeLitUrl } from './endpoint-version';
78+
import { LogLevel } from '@lit-protocol/logger';
7779

7880
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7981
type Listener = (...args: any[]) => void;
@@ -199,7 +201,10 @@ export class LitCore {
199201

200202
// -- set global variables
201203
globalThis.litConfig = this.config;
202-
bootstrapLogManager('core');
204+
bootstrapLogManager(
205+
'core',
206+
this.config.debug ? LogLevel.DEBUG : LogLevel.OFF
207+
);
203208

204209
// -- configure local storage if not present
205210
// LitNodeClientNodejs is a base for LitNodeClient
@@ -674,7 +679,12 @@ export class LitCore {
674679
this.config.bootstrapUrls.length
675680
} nodes. Please check your network connection and try again. Note that you can control this timeout with the connectTimeout config option which takes milliseconds.`;
676681

677-
reject(new InitError({}, msg));
682+
try {
683+
throw new InitError({}, msg);
684+
} catch (e) {
685+
logErrorWithRequestId(requestId, e);
686+
reject(e);
687+
}
678688
}, this.config.connectTimeout);
679689
}),
680690
Promise.all(

packages/logger/src/lib/logger.spec.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ describe('logger', () => {
111111
}
112112

113113
expect(lm.getLogsForId('foo7').length).toEqual(count);
114-
expect(lm.LoggerIds.size).toEqual(1);
114+
expect(lm.LoggerIds.length).toEqual(10);
115+
});
116+
117+
it('should order logs based on logger creation timestamp', async () => {
118+
const loggerA = lm.get('a', '1');
119+
await new Promise((res) => setTimeout(res, 100));
120+
const loggerB = lm.get('b', '2');
121+
122+
const requestIds = lm.LoggerIds;
123+
124+
expect(requestIds.length).toBe(2);
125+
expect(loggerA.timestamp).toEqual(requestIds[0]);
126+
expect(loggerB.timestamp).toEqual(requestIds[1]);
115127
});
116128
});

packages/logger/src/lib/logger.ts

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import { version, LOG_LEVEL, LOG_LEVEL_VALUES } from '@lit-protocol/constants';
22
import { hashMessage } from 'ethers/lib/utils';
33

4-
export { LOG_LEVEL };
4+
export enum LogLevel {
5+
OFF = -1,
6+
ERROR = 0,
7+
INFO = 1,
8+
DEBUG = 2,
9+
WARN = 3,
10+
FATAL = 4,
11+
TIMING_START = 5,
12+
TIMING_END = 6,
13+
}
514

615
const colours = {
716
reset: '\x1b[0m',
@@ -197,6 +206,7 @@ export class Logger {
197206
private _config: Record<string, any> | undefined;
198207
private _isParent: boolean;
199208
private _children: Map<string, Logger>;
209+
private _timestamp: number;
200210

201211
public static createLogger(
202212
category: string,
@@ -222,6 +232,7 @@ export class Logger {
222232
this._config = config;
223233
this._children = new Map();
224234
this._isParent = isParent;
235+
this._timestamp = Date.now();
225236
}
226237

227238
get id(): string {
@@ -232,6 +243,10 @@ export class Logger {
232243
return this._category;
233244
}
234245

246+
get timestamp(): number {
247+
return this._timestamp;
248+
}
249+
235250
get Logs(): Log[] {
236251
return this._logs;
237252
}
@@ -305,14 +320,17 @@ export class Logger {
305320

306321
const arrayLog = log.toArray();
307322
if (this._config?.['condenseLogs'] && !this._checkHash(log)) {
308-
(this._level >= level || level === LOG_LEVEL.ERROR) &&
323+
(this._level >= level || level === LogLevel.ERROR) &&
324+
this._consoleHandler &&
309325
this._consoleHandler(...arrayLog);
310326
(this._level >= level || level === LOG_LEVEL.ERROR) &&
311327
this._handler &&
312328
this._handler(log);
313-
(this._level >= level || level === LOG_LEVEL.ERROR) && this._addLog(log);
329+
330+
(this._level >= level || level === LogLevel.ERROR) && this._addLog(log);
314331
} else if (!this._config?.['condenseLogs']) {
315-
(this._level >= level || level === LOG_LEVEL.ERROR) &&
332+
(this._level >= level || level === LogLevel.ERROR) &&
333+
this._consoleHandler &&
316334
this._consoleHandler(...arrayLog);
317335
(this._level >= level || level === LOG_LEVEL.ERROR) &&
318336
this._handler &&
@@ -336,7 +354,6 @@ export class Logger {
336354

337355
private _addLog(log: Log) {
338356
this._logs.push(log);
339-
340357
// TODO: currently we are not deleting old request id's which over time will fill local storage as the maximum storage size is 10mb
341358
// we should be deleting keys from the front of the collection of `Object.keys(category)` such that the first keys entered are deleted when we reach a pre defined key threshold
342359
// this implementation assumes that serialization / deserialization from `localStorage` keeps the same key ordering in each `category` object as we will asssume the array produced from `Object.keys` will always be the same ordering.
@@ -421,14 +438,20 @@ export class LogManager {
421438
}
422439

423440
get LoggerIds(): string[] {
424-
const keys: string[] = [];
441+
const keys: [string, number][] = [];
425442
for (const category of this._loggers.entries()) {
426443
for (const child of category[1].Children) {
427-
keys.push(child[0]);
444+
keys.push([child[0], child[1].timestamp]);
428445
}
429446
}
430447

431-
return keys;
448+
return keys
449+
.sort((a: [string, number], b: [string, number]) => {
450+
return a[1] - b[1];
451+
})
452+
.map((value: [string, number]) => {
453+
return value[0];
454+
});
432455
}
433456

434457
// if a logger is given an id it will persist logs under its logger instance

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
/**

0 commit comments

Comments
 (0)