-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add pkp-sui * feat: add pkp-sui test * fix typo * change to use bs58 * fix pkp-sui test fix typo Devnet is reset weekly, Testnet was reset on May 11 --------- Co-authored-by: Yoonhyoung-Lee <54613623+Yoonhyoung-Lee@users.noreply.github.com>
- Loading branch information
Showing
18 changed files
with
681 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@nrwl/web/babel", | ||
{ | ||
"useBuiltIns": "usage" | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# pkp-sui | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Building | ||
|
||
Run `nx build pkp-sui` to build the library. | ||
|
||
## Running unit tests | ||
|
||
Run `nx test pkp-sui` to execute the unit tests via [Jest](https://jestjs.io). | ||
If test 3,4 fail, It means sui testnet has been reset. Use sui testnet faucet to get some sui and try again. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: 'pkp-sui', | ||
preset: '../../jest.preset.js', | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: '<rootDir>/tsconfig.spec.json', | ||
}, | ||
}, | ||
transform: { | ||
'^.+\\.[tj]s$': 'ts-jest', | ||
}, | ||
moduleFileExtensions: ['ts', 'js', 'html'], | ||
coverageDirectory: '../../coverage/packages/pkp-sui', | ||
setupFilesAfterEnv: ['../../jest.setup.js'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "@lit-protocol/pkp-sui", | ||
"version": "0.0.1", | ||
"type": "commonjs", | ||
"license": "MIT", | ||
"homepage": "https://github.com/Lit-Protocol/js-sdk", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Lit-Protocol/js-sdk" | ||
}, | ||
"keywords": [ | ||
"library" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/Lit-Protocol/js-sdk/issues" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"directory": "../../dist/packages/pkp-sui" | ||
}, | ||
"main": "./dist/src/index.js", | ||
"typings": "./dist/src/index.d.ts", | ||
"browser": { | ||
"crypto": false, | ||
"stream": false | ||
}, | ||
"tags": [ | ||
"universal" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{ | ||
"name": "pkp-sui", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "packages/pkp-sui/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"command": "yarn build:target pkp-sui" | ||
} | ||
}, | ||
"_buildTsc": { | ||
"executor": "@nrwl/js:tsc", | ||
"outputs": [ | ||
"{options.outputPath}" | ||
], | ||
"options": { | ||
"outputPath": "dist/packages/pkp-sui", | ||
"main": "packages/pkp-sui/src/index.ts", | ||
"tsConfig": "packages/pkp-sui/tsconfig.lib.json", | ||
"assets": [ | ||
"packages/pkp-sui/*.md" | ||
] | ||
} | ||
}, | ||
"_buildWeb": { | ||
"executor": "@websaam/nx-esbuild:package", | ||
"options": { | ||
"globalName": "LitJsSdk_pkpSui", | ||
"outfile": "dist/packages/pkp-sui-vanilla/pkp-sui.js", | ||
"entryPoints": [ | ||
"./packages/pkp-sui/src/index.ts" | ||
], | ||
"define": { | ||
"process.env.NODE_DEBUG": "false", | ||
"global": "window" | ||
}, | ||
"plugins": [ | ||
{ | ||
"package": "esbuild-node-builtins", | ||
"function": "nodeBuiltIns" | ||
} | ||
] | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nrwl/linter:eslint", | ||
"outputs": [ | ||
"{options.outputFile}" | ||
], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"packages/pkp-sui/**/*.ts" | ||
] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nrwl/jest:jest", | ||
"outputs": [ | ||
"coverage/packages/pkp-sui" | ||
], | ||
"options": { | ||
"jestConfig": "packages/pkp-sui/jest.config.ts", | ||
"passWithNoTests": true | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { PKPSuiWallet } from './lib/pkp-sui'; | ||
|
||
export { PKPSuiWallet }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { hashTypedData } from './hash'; | ||
import bs58 from 'bs58'; | ||
|
||
|
||
/** | ||
* Generate transaction digest. | ||
* | ||
* @param bytes BCS serialized transaction data | ||
* @returns transaction digest. | ||
*/ | ||
export function getDigestFromBytes(bytes: Uint8Array) { | ||
const hash = hashTypedData('TransactionData', bytes); | ||
return bs58.encode(hash); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { blake2b } from '@noble/hashes/blake2b'; | ||
|
||
/** | ||
* Generates a Blake2b hash of typed data as a base64 string. | ||
* | ||
* @param typeTag type tag (e.g. TransactionData, SenderSignedData) | ||
* @param data data to hash | ||
*/ | ||
export function hashTypedData(typeTag: string, data: Uint8Array): Uint8Array { | ||
const typeTagBytes = Array.from(`${typeTag}::`).map((e) => e.charCodeAt(0)); | ||
|
||
const dataWithTag = new Uint8Array(typeTagBytes.length + data.length); | ||
dataWithTag.set(typeTagBytes); | ||
dataWithTag.set(data, typeTagBytes.length); | ||
|
||
return blake2b(dataWithTag, { dkLen: 32 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { | ||
JsonRpcProvider, | ||
testnetConnection, | ||
TransactionBlock, | ||
} from '@mysten/sui.js'; | ||
|
||
import * as LITCONFIG from 'lit.config.json'; | ||
|
||
jest.useRealTimers(); | ||
|
||
describe('PKPSuiWallet', () => { | ||
it('should create a wallet', async () => { | ||
const { PKPSuiWallet } = await import('./pkp-sui'); | ||
const wallet = new PKPSuiWallet( | ||
{ | ||
controllerAuthSig: LITCONFIG.CONTROLLER_AUTHSIG, | ||
pkpPubKey: LITCONFIG.PKP_PUBKEY, | ||
}, | ||
new JsonRpcProvider(testnetConnection) | ||
); | ||
const address = await wallet.getAddress(); | ||
expect(address).toEqual(LITCONFIG.PKP_SUI_ADDRESS); | ||
}); | ||
it('should connects to lit node client', async () => { | ||
const { PKPSuiWallet } = await import('./pkp-sui'); | ||
const wallet = new PKPSuiWallet( | ||
{ | ||
controllerAuthSig: LITCONFIG.CONTROLLER_AUTHSIG, | ||
pkpPubKey: LITCONFIG.PKP_PUBKEY, | ||
}, | ||
new JsonRpcProvider(testnetConnection) | ||
); | ||
await wallet.init(); | ||
expect(wallet.litNodeClientReady).toEqual(true); | ||
}); | ||
it('should retrieve account balance', async () => { | ||
const { PKPSuiWallet } = await import('./pkp-sui'); | ||
const provider = new JsonRpcProvider(testnetConnection); | ||
const wallet = new PKPSuiWallet( | ||
{ | ||
controllerAuthSig: LITCONFIG.CONTROLLER_AUTHSIG, | ||
pkpPubKey: LITCONFIG.PKP_PUBKEY, | ||
}, | ||
provider | ||
); | ||
const address = await wallet.getAddress(); | ||
const balance = await provider.getBalance({ | ||
owner: address, | ||
}); | ||
expect(parseInt(balance.totalBalance)).toBeGreaterThanOrEqual(1000); | ||
}); | ||
|
||
it('should send a transaction to itself', async () => { | ||
const { PKPSuiWallet } = await import('./pkp-sui'); | ||
const wallet = new PKPSuiWallet( | ||
{ | ||
controllerAuthSig: LITCONFIG.CONTROLLER_AUTHSIG, | ||
pkpPubKey: LITCONFIG.PKP_PUBKEY, | ||
}, | ||
new JsonRpcProvider(testnetConnection) | ||
); | ||
const address = await wallet.getAddress(); | ||
const tx = new TransactionBlock(); | ||
const [coin] = tx.splitCoins(tx.gas, [tx.pure(1000)]); | ||
tx.transferObjects([coin], tx.pure(address)); | ||
|
||
const dryTransaction = await wallet.dryRunTransactionBlock({ | ||
transactionBlock: tx, | ||
}); | ||
|
||
expect(dryTransaction.effects.status.status).toEqual('success'); | ||
|
||
// This will only send a transaction if the test flag is set to true | ||
if (LITCONFIG.test.sendRealTxThatCostsMoney) { | ||
const transaction = await wallet.signAndExecuteTransactionBlock({ | ||
transactionBlock: tx, | ||
}); | ||
expect(transaction.digest).toBeDefined(); | ||
// expect transaction.digest to be string of length 44 | ||
expect(transaction.digest.length).toEqual(44); | ||
} | ||
|
||
}, 60000); | ||
}); |
Oops, something went wrong.
b513362
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
html-test-app-lit-js-sdk-v2 – ./
html-test-app-lit-js-sdk-v2.vercel.app
html-test-app-lit-js-sdk-v2-git-master-lit-protocol.vercel.app
html-test-app-lit-js-sdk-v2-lit-protocol.vercel.app
test.lit-js-sdk-v2.html.litprotocol.com