Skip to content

Commit

Permalink
Add EdgeCurrencyWallet.signBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-edge authored and swansontec committed Jul 29, 2024
1 parent 170305c commit 7919707
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- added: `EdgeCurrencyWallet.signBytes` to sign raw bytes with a private key.
- changed: Randomize data-sync start times.

## 2.9.2 (2024-07-25)
Expand Down
26 changes: 26 additions & 0 deletions src/core/currency/wallet/currency-wallet-api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { div, eq, mul } from 'biggystring'
import { Disklet } from 'disklet'
import { base64 } from 'rfc4648'
import { bridgifyObject, onMethod, watchMethod } from 'yaob'

import {
Expand Down Expand Up @@ -532,6 +533,31 @@ export function makeCurrencyWalletApi(
)
},

async signBytes(
bytes: Uint8Array,
opts: EdgeSignMessageOptions = {}
): Promise<string> {
const privateKeys = walletInfo.keys

if (engine.signBytes != null) {
return await engine.signBytes(bytes, privateKeys, opts)
}

// Various plugins expect specific encodings for signing messages
// (base16, base64, etc).
// Do the conversion here temporarily if `signMessage` is implemented
// while we migrate to `signBytes`.
else if (pluginId === 'bitcoin' && engine.signMessage != null) {
return await engine.signMessage(
base64.stringify(bytes),
privateKeys,
opts
)
}

throw new Error(`${pluginId} doesn't support signBytes`)
},

async signMessage(
message: string,
opts: EdgeSignMessageOptions = {}
Expand Down
24 changes: 20 additions & 4 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -972,8 +972,8 @@ export interface EdgeCurrencyEngine {
) => Promise<EdgePaymentProtocolInfo>

// Signing:
readonly signMessage?: (
message: string,
readonly signBytes?: (
bytes: Uint8Array,
privateKeys: JsonObject,
opts: EdgeSignMessageOptions
) => Promise<string>
Expand Down Expand Up @@ -1001,6 +1001,16 @@ export interface EdgeCurrencyEngine {

/** @deprecated Provide EdgeCurrencyTools.getDisplayPublicKey: */
readonly getDisplayPublicSeed?: () => string | null

/**
* @deprecated Replaced by `signBytes`.
* Various plugins implement this function with inconsistent encodings.
*/
readonly signMessage?: (
message: string,
privateKeys: JsonObject,
opts: EdgeSignMessageOptions
) => Promise<string>
}

// currency plugin -----------------------------------------------------
Expand Down Expand Up @@ -1216,8 +1226,8 @@ export interface EdgeCurrencyWallet {
) => Promise<EdgeTransaction>

// Signing:
readonly signMessage: (
message: string,
readonly signBytes: (
buf: Uint8Array,
opts?: EdgeSignMessageOptions
) => Promise<string>

Expand All @@ -1240,6 +1250,12 @@ export interface EdgeCurrencyWallet {

// Generic:
readonly otherMethods: EdgeOtherMethods

/** @deprecated Use `signBytes` instead. */
readonly signMessage: (
message: string,
opts?: EdgeSignMessageOptions
) => Promise<string>
}

export interface EdgeMemoryWallet {
Expand Down

0 comments on commit 7919707

Please sign in to comment.