Skip to content

Commit

Permalink
Merge branch 'master' into feature/drel-378-tg-osmosis-team-facing-is…
Browse files Browse the repository at this point in the history
…sues-with-sdk-utility-method
  • Loading branch information
Ansonhkg authored Dec 23, 2024
2 parents 5116b9d + b393fb2 commit 4c2ec24
Show file tree
Hide file tree
Showing 35 changed files with 78 additions and 36 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ If you're a tech-savvy user and wish to utilize only specific submodules that ou
| [@lit-protocol/core](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/core) | ![core](https://img.shields.io/badge/-universal-8A6496 'core') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/core"><img src="https://img.shields.io/npm/v/@lit-protocol/core"/></a> |
| [@lit-protocol/crypto](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/crypto) | ![crypto](https://img.shields.io/badge/-universal-8A6496 'crypto') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/crypto"><img src="https://img.shields.io/npm/v/@lit-protocol/crypto"/></a> |
| [@lit-protocol/encryption](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/encryption) | ![encryption](https://img.shields.io/badge/-universal-8A6496 'encryption') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/encryption"><img src="https://img.shields.io/npm/v/@lit-protocol/encryption"/></a> |
| [@lit-protocol/event-listener](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/event-listener) | ![event-listener](https://img.shields.io/badge/-universal-8A6496 'event-listener') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/event-listener"><img src="https://img.shields.io/npm/v/@lit-protocol/event-listener"/></a> |
| [@lit-protocol/logger](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/logger) | ![logger](https://img.shields.io/badge/-universal-8A6496 'logger') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/logger"><img src="https://img.shields.io/npm/v/@lit-protocol/logger"/></a> |
| [@lit-protocol/misc](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc) | ![misc](https://img.shields.io/badge/-universal-8A6496 'misc') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/misc"><img src="https://img.shields.io/npm/v/@lit-protocol/misc"/></a> |
| [@lit-protocol/nacl](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/nacl) | ![nacl](https://img.shields.io/badge/-universal-8A6496 'nacl') | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/nacl"><img src="https://img.shields.io/npm/v/@lit-protocol/nacl"/></a> |
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useNx": true,
"useWorkspaces": true,
"version": "7.0.2"
"version": "7.0.3"
}
2 changes: 1 addition & 1 deletion packages/access-control-conditions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"tags": [
"universal"
],
"version": "7.0.2",
"version": "7.0.3",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
2 changes: 1 addition & 1 deletion packages/auth-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"tags": [
"browser"
],
"version": "7.0.2",
"version": "7.0.3",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
2 changes: 1 addition & 1 deletion packages/auth-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"crypto": false,
"stream": false
},
"version": "7.0.2",
"version": "7.0.3",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
2 changes: 1 addition & 1 deletion packages/constants/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"tags": [
"universal"
],
"version": "7.0.2",
"version": "7.0.3",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
2 changes: 1 addition & 1 deletion packages/constants/src/lib/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = '7.0.2';
export const version = '7.0.3';
2 changes: 1 addition & 1 deletion packages/contracts-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"tags": [
"universal"
],
"version": "7.0.2",
"version": "7.0.3",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lit-protocol/core",
"version": "7.0.2",
"version": "7.0.3",
"type": "commonjs",
"license": "MIT",
"homepage": "https://github.com/Lit-Protocol/js-sdk",
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"tags": [
"universal"
],
"version": "7.0.2",
"version": "7.0.3",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
2 changes: 1 addition & 1 deletion packages/encryption/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"crypto": false,
"stream": false
},
"version": "7.0.2",
"version": "7.0.3",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
2 changes: 1 addition & 1 deletion packages/event-listener/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"scripts": {
"generate-lit-actions": "yarn node ./esbuild.config.js"
},
"version": "7.0.2",
"version": "7.0.3",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
2 changes: 1 addition & 1 deletion packages/lit-auth-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lit-protocol/lit-auth-client",
"version": "7.0.2",
"version": "7.0.3",
"type": "commonjs",
"license": "MIT",
"homepage": "https://github.com/Lit-Protocol/js-sdk",
Expand Down
2 changes: 1 addition & 1 deletion packages/lit-node-client-nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"tags": [
"nodejs"
],
"version": "7.0.2",
"version": "7.0.3",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
2 changes: 1 addition & 1 deletion packages/lit-node-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"crypto": false,
"stream": false
},
"version": "7.0.2",
"version": "7.0.3",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
2 changes: 1 addition & 1 deletion packages/logger/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lit-protocol/logger",
"version": "7.0.2",
"version": "7.0.3",
"type": "commonjs",
"tags": [
"universal"
Expand Down
2 changes: 1 addition & 1 deletion packages/misc-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"tags": [
"browser"
],
"version": "7.0.2",
"version": "7.0.3",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
2 changes: 1 addition & 1 deletion packages/misc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"tags": [
"universal"
],
"version": "7.0.2",
"version": "7.0.3",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
2 changes: 1 addition & 1 deletion packages/nacl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"access": "public",
"directory": "../../dist/packages/nacl"
},
"version": "7.0.2",
"version": "7.0.3",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
2 changes: 1 addition & 1 deletion packages/pkp-base/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lit-protocol/pkp-base",
"version": "7.0.2",
"version": "7.0.3",
"type": "commonjs",
"license": "MIT",
"homepage": "https://github.com/Lit-Protocol/js-sdk",
Expand Down
2 changes: 1 addition & 1 deletion packages/pkp-cosmos/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lit-protocol/pkp-cosmos",
"version": "7.0.2",
"version": "7.0.3",
"type": "commonjs",
"license": "MIT",
"homepage": "https://github.com/Lit-Protocol/js-sdk",
Expand Down
2 changes: 1 addition & 1 deletion packages/pkp-ethers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"tags": [
"universal"
],
"version": "7.0.2",
"version": "7.0.3",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
2 changes: 1 addition & 1 deletion packages/pkp-sui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lit-protocol/pkp-sui",
"version": "7.0.2",
"version": "7.0.3",
"type": "commonjs",
"license": "MIT",
"homepage": "https://github.com/Lit-Protocol/js-sdk",
Expand Down
2 changes: 1 addition & 1 deletion packages/pkp-walletconnect/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lit-protocol/pkp-walletconnect",
"version": "7.0.2",
"version": "7.0.3",
"type": "commonjs",
"license": "MIT",
"homepage": "https://github.com/Lit-Protocol/js-sdk",
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"buildOptions": {
"genReact": false
},
"version": "7.0.2",
"version": "7.0.3",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
2 changes: 1 addition & 1 deletion packages/uint8arrays/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"tags": [
"universal"
],
"version": "7.0.2",
"version": "7.0.3",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
2 changes: 1 addition & 1 deletion packages/wasm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lit-protocol/wasm",
"version": "7.0.2",
"version": "7.0.3",
"type": "commonjs",
"homepage": "https://github.com/Lit-Protocol/js-sdk",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/wrapped-keys-lit-actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"scripts": {
"generate-lit-actions": "yarn node ./esbuild.config.js"
},
"version": "7.0.2",
"version": "7.0.3",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Connection,
Keypair,
Transaction,
VersionedTransaction,
} from '@solana/web3.js';

// Solana transactions are pre-serialized; much simpler API than ethereum transactions
Expand Down Expand Up @@ -31,7 +32,7 @@ export function validateUnsignedTransaction(
}
}

function signTransaction({
function signLegacyTransaction({
solanaKeyPair,
transaction,
}: {
Expand All @@ -45,18 +46,36 @@ function signTransaction({
throw new Error('Transaction signature is null');
}

return { signature: ethers.utils.base58.encode(transaction.signature) };
return ethers.utils.base58.encode(transaction.signature);
} catch (err: unknown) {
throw new Error(`When signing transaction - ${(err as Error).message}`);
}
}
function signVersionedTransaction({
solanaKeyPair,
transaction,
}: {
solanaKeyPair: Keypair;
transaction: VersionedTransaction;
}) {
try {
transaction.sign([solanaKeyPair]);

if (!transaction.signatures.length) {
throw new Error('Transaction signature is null');
}

return ethers.utils.base58.encode(transaction.signatures[0]);
} catch (err: unknown) {
throw new Error(`When signing transaction - ${(err as Error).message}`);
}
}
async function sendTransaction({
chain,
transaction,
}: {
chain: Cluster;
transaction: Transaction;
transaction: Transaction | VersionedTransaction;
}) {
try {
const solanaConnection = new Connection(clusterApiUrl(chain), 'confirmed');
Expand All @@ -70,20 +89,32 @@ export async function signTransactionSolanaKey({
broadcast,
privateKey,
unsignedTransaction,
versionedTransaction,
}: {
broadcast: boolean;
privateKey: string;
unsignedTransaction: UnsignedTransaction;
versionedTransaction?: boolean;
}) {
// Be sure you call validateUnsignedTransaction(unsignedTransaction); before calling this method!

const solanaKeyPair = Keypair.fromSecretKey(Buffer.from(privateKey, 'hex'));

const transaction = Transaction.from(
Buffer.from(unsignedTransaction.serializedTransaction, 'base64')
);

const { signature } = signTransaction({ transaction, solanaKeyPair });
let transaction;
let signature;
if (versionedTransaction) {
const swapTransactionBuf = Buffer.from(
unsignedTransaction.serializedTransaction,
'base64'
);
transaction = VersionedTransaction.deserialize(swapTransactionBuf);
signature = signVersionedTransaction({ transaction, solanaKeyPair });
} else {
transaction = Transaction.from(
Buffer.from(unsignedTransaction.serializedTransaction, 'base64')
);
signature = signLegacyTransaction({ transaction, solanaKeyPair });
}

if (!broadcast) {
return signature;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface SignTransactionWithEncryptedSolanaKeyParams {
dataToEncryptHash: string; // The hash of the data to encrypt
unsignedTransaction: UnsignedTransaction;
broadcast: boolean; // Flag to determine if the transaction should be broadcasted
versionedTransaction?: boolean; // Flag to determine if the transaction is a versioned one or a legacy one
}

/**
Expand All @@ -28,6 +29,7 @@ export async function signTransactionWithEncryptedSolanaKey({
dataToEncryptHash,
unsignedTransaction,
broadcast,
versionedTransaction,
}: SignTransactionWithEncryptedSolanaKeyParams): Promise<string> {
validateUnsignedTransaction(unsignedTransaction);

Expand All @@ -41,5 +43,6 @@ export async function signTransactionWithEncryptedSolanaKey({
broadcast,
privateKey,
unsignedTransaction,
versionedTransaction,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ declare const ciphertext: SignTransactionWithEncryptedSolanaKeyParams['ciphertex
declare const dataToEncryptHash: SignTransactionWithEncryptedSolanaKeyParams['dataToEncryptHash'];
declare const unsignedTransaction: SignTransactionWithEncryptedSolanaKeyParams['unsignedTransaction'];
declare const broadcast: SignTransactionWithEncryptedSolanaKeyParams['broadcast'];
declare const versionedTransaction: SignTransactionWithEncryptedSolanaKeyParams['versionedTransaction'];

(async () =>
litActionHandler(async () =>
Expand All @@ -20,5 +21,6 @@ declare const broadcast: SignTransactionWithEncryptedSolanaKeyParams['broadcast'
dataToEncryptHash,
unsignedTransaction,
broadcast,
versionedTransaction,
})
))();
2 changes: 1 addition & 1 deletion packages/wrapped-keys/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"buildOptions": {
"genReact": false
},
"version": "7.0.2",
"version": "7.0.3",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SignTransactionWithEncryptedKeyParams } from '../types';
* Signs a transaction inside the Lit Action using the previously persisted wrapped key associated with the current LIT PK.
* This method fetches the encrypted key from the wrapped keys service, then executes a Lit Action that decrypts the key inside the LIT action and uses
* the decrypted key to sign the provided transaction
* use `versionedTransaction: true` to sign a versioned transaction and `false` for a legacy one
* Optionally, if you pass `broadcast: true`, the LIT action will also submit the signed transaction to the associated RPC endpoint on your behalf
*
* @param { SignTransactionWithEncryptedKeyParams } params Parameters required to sign the requested transaction
Expand Down
Loading

0 comments on commit 4c2ec24

Please sign in to comment.