Skip to content

Commit e666ce3

Browse files
authored
Merge branch 'staging/v7' into feature/lit-3918-no-globalthis-variables-anymore
Signed-off-by: Anson <[email protected]>
2 parents 9a5abd3 + c9d6c0d commit e666ce3

File tree

13 files changed

+845
-935
lines changed

13 files changed

+845
-935
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: 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/core/src/lib/lit-core.ts

Lines changed: 14 additions & 4 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,
@@ -75,6 +76,7 @@ import {
7576
} from '@lit-protocol/types';
7677

7778
import { composeLitUrl } from './endpoint-version';
79+
import { LogLevel } from '@lit-protocol/logger';
7880

7981
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8082
type Listener = (...args: any[]) => void;
@@ -198,9 +200,12 @@ export class LitCore {
198200
// -- set bootstrapUrls to match the network litNetwork unless it's set to custom
199201
this.setCustomBootstrapUrls();
200202

201-
// -- set misc global variables
202-
setMiscLitConfig(this.config);
203-
bootstrapLogManager('core');
203+
// -- set global variables
204+
globalThis.litConfig = this.config;
205+
bootstrapLogManager(
206+
'core',
207+
this.config.debug ? LogLevel.DEBUG : LogLevel.OFF
208+
);
204209

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

675-
reject(new InitError({}, msg));
680+
try {
681+
throw new InitError({}, msg);
682+
} catch (e) {
683+
logErrorWithRequestId(requestId, e);
684+
reject(e);
685+
}
676686
}, this.config.connectTimeout);
677687
}),
678688
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)