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 a62d546 commit 7eb4eda
Show file tree
Hide file tree
Showing 9 changed files with 833 additions and 2 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
5 changes: 4 additions & 1 deletion libs/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"description": "SDK for interacting directly with the Sia network from browsers and web clients.",
"version": "0.0.2",
"license": "MIT",
"dependencies": {},
"dependencies": {
"@siafoundation/react-walletd": "3.0.0",
"@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,
}
}
56 changes: 56 additions & 0 deletions libs/sdk/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { ConsensusNetwork, ConsensusState } from '@siafoundation/react-walletd'
import { Transaction, UnlockConditions } from '@siafoundation/types'

type Currency = string
type Signature = string
type Address = string
Expand Down Expand Up @@ -144,4 +147,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
) => {
transaction?: Transaction
error?: string
}
transactionId: (txn: Transaction) => {
id?: string
error?: string
}
}
}
Loading

0 comments on commit 7eb4eda

Please sign in to comment.