Skip to content

Commit

Permalink
refactor: migrate wallet wasm into sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Mar 19, 2024
1 parent e4d5595 commit 4aba9ba
Show file tree
Hide file tree
Showing 10 changed files with 890 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-carrots-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siafoundation/sdk': minor
---

Wallet and transaction signing methods are now part of the sdk.
2 changes: 1 addition & 1 deletion apps/walletd/lib/testMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export function getConsensusState() {
return {
index: {
height: 45962,
ID: 'bid:000000000cb8ef1dfeb66afa78bc0b3b2d1a7a1df948efba22f7fc1a5571e79f',
id: 'bid:000000000cb8ef1dfeb66afa78bc0b3b2d1a7a1df948efba22f7fc1a5571e79f',
},
prevTimestamps: [
'2023-11-28T11:34:49-05:00',
Expand Down
13 changes: 11 additions & 2 deletions libs/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

SDK for interacting directly with the Sia network from browsers and web clients.

## Running unit tests
## Installation

Run `nx test sdk` to execute the unit tests via [Jest](https://jestjs.io).
`npm install @siafoundation/sdk`

## Usage

```js
import { initSDK } from '@siafoundation/sdk'

const sdk = await initSDK()
const { phrase, error } = sdk.wallet.generateSeedPhrase()
```
3 changes: 3 additions & 0 deletions libs/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"description": "SDK for interacting directly with the Sia network from browsers and web clients.",
"version": "0.0.2",
"license": "MIT",
"dependencies": {
"@siafoundation/types": "0.1.3"
},
"devDependencies": {
"undici": "5.28.3"
},
Expand Down
1 change: 1 addition & 0 deletions libs/sdk/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export function getSDK() {
const wasm = (global as any).sia as WASM
return {
rhp: wasm.rhp,
wallet: wasm.wallet,
WebTransportClient,
}
}
60 changes: 60 additions & 0 deletions libs/sdk/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import {
Transaction,
UnlockConditions,
ConsensusNetwork,
ConsensusState,
} from '@siafoundation/types'

type Currency = string
type Signature = string
type Address = string
Expand Down Expand Up @@ -144,4 +151,57 @@ export type WASM = {
error?: string
}
}
wallet: {
generateSeedPhrase: () => {
phrase?: string
error?: string
}
generateKeyPair: () => {
privateKey?: string
publicKey?: string
error?: string
}
keyPairFromSeedPhrase: (
phrase: string,
index: number
) => {
privateKey?: string
publicKey?: string
error?: string
}
standardUnlockConditions: (publicKey: string) => {
unlockConditions?: UnlockConditions
error?: string
}
standardUnlockHash: (publicKey: string) => {
address?: string
error?: string
}
addressFromUnlockConditions: (unlockConditions: UnlockConditions) => {
address?: string
error?: string
}
addressFromSpendPolicy: (spendPolicy: string) => {
address?: string
error?: string
}
encodeTransaction: (txn: Transaction) => {
encodedTransaction?: string
error?: string
}
signTransaction: (
cs: ConsensusState,
cn: ConsensusNetwork,
txn: Transaction,
sigIndex: number,
privateKey: string
) => {
signature?: string
error?: string
}
transactionId: (txn: Transaction) => {
id?: string
error?: string
}
}
}
Loading

0 comments on commit 4aba9ba

Please sign in to comment.