Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove lit-siwe #365

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,6 @@ jobs:
run: yarn build
- name: Run Unit tests
run: yarn tools --test --unit
linter:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'yarn'
- name: Install project dependencies
run: yarn install
- name: Lint
run: yarn nx format:check --all
e2e-connection:
runs-on: ubuntu-latest
timeout-minutes: 30
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: lint
on:
pull_request:
push:
branches:
- master
jobs:
linter:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'yarn'
- name: Install project dependencies
run: yarn install
- name: Lint
run: yarn nx format:check --all
158 changes: 79 additions & 79 deletions apps/nodejs/manual-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as LitJsSdk from '@lit-protocol/lit-node-client';
// import { LitContracts } from '@lit-protocol/contracts-sdk';
import { ethers } from 'ethers';
import { PKPEthersWallet } from '@lit-protocol/pkp-ethers';
import { SiweMessage } from 'lit-siwe';
import { SiweMessage } from 'siwe';
import { LIT_EVM_CHAINS } from '@lit-protocol/constants';


Expand Down Expand Up @@ -206,30 +206,30 @@ const runLogic = async (contract: LitContracts) => {
// };

const pkpSign = async (client, pkpPubkey, authSig) => {
// try and sign something
let sig = await client.pkpSign({
toSign: ethers.utils.arrayify(ethers.utils.keccak256([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100])), // hello world in Uint8Array
pubKey: pkpPubkey,
authSig,
});
// try and sign something
let sig = await client.pkpSign({
toSign: ethers.utils.arrayify(ethers.utils.keccak256([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100])), // hello world in Uint8Array
pubKey: pkpPubkey,
authSig,
});

// console.log("sig: ", sig);
// console.log("sig: ", sig);

const recoveredPk = ethers.utils.recoverPublicKey("0x" + sig.dataSigned, sig.signature);
const addr = ethers.utils.computeAddress('0x' + sig.publicKey);
const recoveredAddr = ethers.utils.computeAddress(recoveredPk);
const claimedAddr = ethers.utils.computeAddress(pkpPubkey);
const recoveredPk = ethers.utils.recoverPublicKey("0x" + sig.dataSigned, sig.signature);
const addr = ethers.utils.computeAddress('0x' + sig.publicKey);
const recoveredAddr = ethers.utils.computeAddress(recoveredPk);
const claimedAddr = ethers.utils.computeAddress(pkpPubkey);

const allGood = addr === recoveredAddr && addr === claimedAddr;
const allGood = addr === recoveredAddr && addr === claimedAddr;

console.log('all addresses match: ', allGood);
return allGood;
console.log('all addresses match: ', allGood);
return allGood;
}

const litActionSign = async(client, pkpPubkey, authSig) => {
console.log('testing sig with lit actions...');
// this code will be run on the node
const litActionCode = `
const litActionSign = async (client, pkpPubkey, authSig) => {
console.log('testing sig with lit actions...');
// this code will be run on the node
const litActionCode = `
const go = async () => {
// this requests a signature share from the Lit Node
// the signature share will be automatically returned in the HTTP response from the node
Expand All @@ -241,40 +241,40 @@ const litActionSign = async(client, pkpPubkey, authSig) => {
go();
`;

const signatures = await client.executeJs({
code: litActionCode,
authSig,
// all jsParams can be used anywhere in your litActionCode
jsParams: {
// this is the string "Hello World" for testing
toSign: ethers.utils.arrayify(ethers.utils.keccak256([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100])),
publicKey: pkpPubkey,
sigName: "sig1",
},
});
// console.log("signatures: ", signatures);
const { sig1, sig2 } = signatures.signatures
const sigKeys = {
sig1: {
recovered: ethers.utils.computeAddress(ethers.utils.recoverPublicKey("0x" + sig1.dataSigned, sig1.signature)),
reported: ethers.utils.computeAddress('0x' + sig1.publicKey)
},
sig2: {
recovered: ethers.utils.computeAddress(ethers.utils.recoverPublicKey("0x" + sig2.dataSigned, sig2.signature)),
reported: ethers.utils.computeAddress('0x' + sig2.publicKey)
},
}
const signatures = await client.executeJs({
code: litActionCode,
authSig,
// all jsParams can be used anywhere in your litActionCode
jsParams: {
// this is the string "Hello World" for testing
toSign: ethers.utils.arrayify(ethers.utils.keccak256([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100])),
publicKey: pkpPubkey,
sigName: "sig1",
},
});
// console.log("signatures: ", signatures);
const { sig1, sig2 } = signatures.signatures
const sigKeys = {
sig1: {
recovered: ethers.utils.computeAddress(ethers.utils.recoverPublicKey("0x" + sig1.dataSigned, sig1.signature)),
reported: ethers.utils.computeAddress('0x' + sig1.publicKey)
},
sig2: {
recovered: ethers.utils.computeAddress(ethers.utils.recoverPublicKey("0x" + sig2.dataSigned, sig2.signature)),
reported: ethers.utils.computeAddress('0x' + sig2.publicKey)
},
}

// console.log(`sigKeys: ${JSON.stringify(sigKeys, null, 2)}`)
// console.log(`sigKeys: ${JSON.stringify(sigKeys, null, 2)}`)

const pkpAddr = ethers.utils.computeAddress(pkpPubkey);
// console.log('pkpAddr:', pkpAddr)
const pkpAddr = ethers.utils.computeAddress(pkpPubkey);
// console.log('pkpAddr:', pkpAddr)


let allGood = sigKeys.sig1.recovered == sigKeys.sig1.reported && sigKeys.sig2.recovered == sigKeys.sig2.reported && sigKeys.sig1.recovered == sigKeys.sig2.recovered && sigKeys.sig1.recovered == pkpAddr;
console.log('all addresses match: ', allGood);
return allGood;
}
let allGood = sigKeys.sig1.recovered == sigKeys.sig1.reported && sigKeys.sig2.recovered == sigKeys.sig2.reported && sigKeys.sig1.recovered == sigKeys.sig2.recovered && sigKeys.sig1.recovered == pkpAddr;
console.log('all addresses match: ', allGood);
return allGood;
}

const mintPkpAndSign = async () => {
let client;
Expand Down Expand Up @@ -321,37 +321,37 @@ const mintPkpAndSign = async () => {

await client.connect();

const litContracts = new LitContracts({
privateKey: TEST_FUNDED_PRIVATE_KEY,
});
const pkpPubkey = await runLogic(litContracts);
console.log('pkpPubkey:', pkpPubkey);

const privateKey = TEST_FUNDED_PRIVATE_KEY;
const provider = new ethers.providers.JsonRpcProvider(
LIT_EVM_CHAINS['chronicleTestnet'].rpcUrls[0]
);
const wallet = new ethers.Wallet(privateKey, provider);
const authSig = await getAuthSig(wallet);

// console.log('Sleeping for 5 seconds so that the chronicle node replica can sync up');
// Sleep for 5 seconds
// await new Promise(resolve => setTimeout(resolve, 5000));


let startTime = Date.now();
let allGood = true;
const testCount = 1;
for(let i = 0; i < testCount; i++){
console.log(`testing ${i + 1} of ${testCount}`);
let result = await pkpSign(client, pkpPubkey, authSig);
if (!result) {
allGood = false;
}
const litContracts = new LitContracts({
privateKey: TEST_FUNDED_PRIVATE_KEY,
});
const pkpPubkey = await runLogic(litContracts);
console.log('pkpPubkey:', pkpPubkey);

const privateKey = TEST_FUNDED_PRIVATE_KEY;
const provider = new ethers.providers.JsonRpcProvider(
LIT_EVM_CHAINS['chronicleTestnet'].rpcUrls[0]
);
const wallet = new ethers.Wallet(privateKey, provider);
const authSig = await getAuthSig(wallet);

// console.log('Sleeping for 5 seconds so that the chronicle node replica can sync up');
// Sleep for 5 seconds
// await new Promise(resolve => setTimeout(resolve, 5000));


let startTime = Date.now();
let allGood = true;
const testCount = 1;
for (let i = 0; i < testCount; i++) {
console.log(`testing ${i + 1} of ${testCount}`);
let result = await pkpSign(client, pkpPubkey, authSig);
if (!result) {
allGood = false;
}
console.log(`it took ${(Date.now() - startTime) / 1000}s to run ${testCount} tests`)
console.log('all tests were good', allGood);
// await litActionSign(client, pkpPubkey, authSig);
}
console.log(`it took ${(Date.now() - startTime) / 1000}s to run ${testCount} tests`)
console.log('all tests were good', allGood);
// await litActionSign(client, pkpPubkey, authSig);
}

const getAuthSig = async (wallet) => {
Expand Down
2 changes: 1 addition & 1 deletion e2e-nodejs/group-rli/test-rli-pkp-as-delegatee.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export async function main() {
resources: resources,
chainId: 1,

// optional (this would use normal siwe lib, without it, it would use lit-siwe)
// optional (this would use normal siwe lib, without it, it would use siwe-recap)
resourceAbilityRequests: resourceAbilityRequests,
});

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@
"ipfs-unixfs-importer": "^12.0.0",
"jose": "^4.14.4",
"jszip": "^3.10.1",
"lit-siwe": "^1.1.8",
"micromodal": "^0.4.10",
"multiformats": "^12.1.3",
"nanoid": "3.3.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/auth-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"peerDependencies": {
"@walletconnect/ethereum-provider": "2.9.2",
"@walletconnect/modal": "2.6.1",
"lit-siwe": "^1.1.8",
"siwe": "^2.0.5",
"tweetnacl": "^1.0.3",
"tweetnacl-util": "^0.13.3",
"util": "^0.12.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/auth-browser/src/lib/chains/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import LitConnectModal from '../connect-modal/modal';

import { Web3Provider, JsonRpcSigner } from '@ethersproject/providers';

import { SiweMessage } from 'lit-siwe';
import { SiweMessage } from 'siwe';
import { getAddress } from 'ethers/lib/utils';

// @ts-ignore: If importing 'nacl' directly, the built files will use .default instead
Expand Down
3 changes: 2 additions & 1 deletion packages/constants/src/lib/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export enum VMTYPE {

export enum SIGTYPE {
BLS = 'BLS',
EcdsaCaitSith = 'ECDSA_CAIT_SITH',
EcdsaK256 = 'K256',
EcdsaCaitSith = 'ECDSA_CAIT_SITH', // Legacy alias of K256
EcdsaCAITSITHP256 = 'EcdsaCaitSithP256',
}

Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/lib/crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('combine ECDSA Shares', () => {
sigName: 'sig',
},
{
sigType: 'ECDSA_CAIT_SITH',
sigType: 'K256',
signatureShare:
'BA77EB500884A60583DEA49578D4BB64BB55EF497F37C88DF935D739CE8E0A9F',
shareIndex: 0,
Expand Down
4 changes: 3 additions & 1 deletion packages/crypto/src/lib/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ export const combineEcdsaShares = (
let res: string = '';
switch (type) {
case SIGTYPE.EcdsaCaitSith:
case SIGTYPE.EcdsaK256:
res = ecdsaSdk.combine_signature(validShares, 2);

try {
Expand All @@ -256,7 +257,7 @@ export const combineEcdsaShares = (

/*
r and s values of the signature should be maximum of 64 bytes
r and s values can have polarity as the first two bits, here we remove
r and s values can have polarity as the first two bits, here we remove
*/
if (sig && sig.r && sig.r.length > 64) {
while (sig.r.length > 64) {
Expand Down Expand Up @@ -298,6 +299,7 @@ export const computeHDPubKey = (
try {
switch (sigType) {
case SIGTYPE.EcdsaCaitSith:
case SIGTYPE.EcdsaK256:
// a bit of pre processing to remove characters which will cause our wasm module to reject the values.
pubkeys = pubkeys.map((value: string) => {
return value.replace('0x', '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
EthWalletAuthenticateOptions,
} from '@lit-protocol/types';
import { LIT_CHAINS, AuthMethodType, LIT_ERROR } from '@lit-protocol/constants';
import { SiweMessage } from 'lit-siwe';
import { SiweMessage } from 'siwe';
import { ethers } from 'ethers';
import { BaseProvider } from './BaseProvider';
import { checkAndSignAuthMessage } from '@lit-protocol/lit-node-client';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ import {

import { computeAddress } from '@ethersproject/transactions';
import { joinSignature, sha256 } from 'ethers/lib/utils';
import { SiweMessage } from 'lit-siwe';
import * as siweNormal from 'siwe';
import siwe from 'siwe';

import { LitCore } from '@lit-protocol/core';
import { IPFSBundledSDK } from '@lit-protocol/lit-third-party-libs';
Expand All @@ -113,7 +112,7 @@ import {
} from '@lit-protocol/misc-browser';
import { nacl } from '@lit-protocol/nacl';
import { BigNumber, ethers, utils } from 'ethers';
import * as siwe from 'siwe';
import { SiweMessage } from 'siwe';

// TODO: move this to auth-helper for next patch
interface CapacityCreditsReq {
Expand Down Expand Up @@ -1298,10 +1297,11 @@ export class LitNodeClientNodeJs extends LitCore {
// -- validate if signature type is ECDSA
if (
sigType !== SIGTYPE.EcdsaCaitSith &&
sigType !== SIGTYPE.EcdsaK256 &&
sigType !== SIGTYPE.EcdsaCAITSITHP256
) {
throwError({
message: `signature type is ${sigType} which is not ECDSA_CAIT_SITH`,
message: `signature type is ${sigType} which is invalid`,
errorKind: LIT_ERROR.UNKNOWN_SIGNATURE_TYPE.kind,
errorCode: LIT_ERROR.UNKNOWN_SIGNATURE_TYPE.name,
});
Expand Down Expand Up @@ -1461,10 +1461,11 @@ export class LitNodeClientNodeJs extends LitCore {
// -- validate if signature type is ECDSA
if (
sigType !== SIGTYPE.EcdsaCaitSith &&
sigType !== SIGTYPE.EcdsaK256 &&
sigType !== SIGTYPE.EcdsaCAITSITHP256
) {
throwError({
message: `signature type is ${sigType} which is not ECDSA_CAIT_SITH`,
message: `signature type is ${sigType} which is invalid`,
errorKind: LIT_ERROR.UNKNOWN_SIGNATURE_TYPE.kind,
errorCode: LIT_ERROR.UNKNOWN_SIGNATURE_TYPE.name,
});
Expand Down Expand Up @@ -2531,7 +2532,7 @@ export class LitNodeClientNodeJs extends LitCore {
});

// regular siwe
siweMessage = new siweNormal.SiweMessage({
siweMessage = new SiweMessage({
domain:
params?.domain || globalThis.location?.host || 'litprotocol.com',
address: pkpEthAddress,
Expand All @@ -2546,7 +2547,7 @@ export class LitNodeClientNodeJs extends LitCore {

siweMessage = recapObject.addToSiweMessage(siweMessage);
} else {
// lit-siwe (NOT regular siwe)
// regular siwe without recap
siweMessage = new SiweMessage({
domain:
params?.domain || globalThis.location?.host || 'litprotocol.com',
Expand Down
Loading
Loading