Skip to content

Commit e3a3ec5

Browse files
Merge pull request #22 from DIG-Network/hex-spend-bundle
Hex spend bundle to coin spends
2 parents fb5783f + d8867fb commit e3a3ec5

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ export declare function oracleDelegatedPuzzle(oraclePuzzleHash: Buffer, oracleFe
359359
* @returns {Promise<Buffer>} The signature.
360360
*/
361361
export declare function signCoinSpends(coinSpends: Array<CoinSpend>, privateKeys: Array<Buffer>, forTestnet: boolean): Buffer
362+
export declare function hexSpendBundleToCoinSpends(hex: string): Array<CoinSpend>
362363
/**
363364
* Computes the ID (name) of a coin.
364365
*

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ if (!nativeBinding) {
310310
throw new Error(`Failed to load native binding`)
311311
}
312312

313-
const { newLineageProof, newEveProof, Tls, Peer, PeerType, selectCoins, sendXch, morphLauncherId, createServerCoin, mintStore, oracleSpend, addFee, masterPublicKeyToWalletSyntheticKey, masterPublicKeyToFirstPuzzleHash, masterSecretKeyToWalletSyntheticSecretKey, secretKeyToPublicKey, puzzleHashToAddress, addressToPuzzleHash, adminDelegatedPuzzleFromKey, writerDelegatedPuzzleFromKey, oracleDelegatedPuzzle, signCoinSpends, getCoinId, updateStoreMetadata, updateStoreOwnership, meltStore, signMessage, verifySignedMessage, syntheticKeyToPuzzleHash, getCost, getMainnetGenesisChallenge, getTestnet11GenesisChallenge, simulatorNewPuzzle, simulatorNewBlspair, simulatorNewProgram } = nativeBinding
313+
const { newLineageProof, newEveProof, Tls, Peer, PeerType, selectCoins, sendXch, morphLauncherId, createServerCoin, mintStore, oracleSpend, addFee, masterPublicKeyToWalletSyntheticKey, masterPublicKeyToFirstPuzzleHash, masterSecretKeyToWalletSyntheticSecretKey, secretKeyToPublicKey, puzzleHashToAddress, addressToPuzzleHash, adminDelegatedPuzzleFromKey, writerDelegatedPuzzleFromKey, oracleDelegatedPuzzle, signCoinSpends, hexSpendBundleToCoinSpends, getCoinId, updateStoreMetadata, updateStoreOwnership, meltStore, signMessage, verifySignedMessage, syntheticKeyToPuzzleHash, getCost, getMainnetGenesisChallenge, getTestnet11GenesisChallenge, simulatorNewPuzzle, simulatorNewBlspair, simulatorNewProgram } = nativeBinding
314314

315315
module.exports.newLineageProof = newLineageProof
316316
module.exports.newEveProof = newEveProof
@@ -334,6 +334,7 @@ module.exports.adminDelegatedPuzzleFromKey = adminDelegatedPuzzleFromKey
334334
module.exports.writerDelegatedPuzzleFromKey = writerDelegatedPuzzleFromKey
335335
module.exports.oracleDelegatedPuzzle = oracleDelegatedPuzzle
336336
module.exports.signCoinSpends = signCoinSpends
337+
module.exports.hexSpendBundleToCoinSpends = hexSpendBundleToCoinSpends
337338
module.exports.getCoinId = getCoinId
338339
module.exports.updateStoreMetadata = updateStoreMetadata
339340
module.exports.updateStoreOwnership = updateStoreOwnership

src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,17 @@ pub fn sign_coin_spends(
13681368
sig.to_js()
13691369
}
13701370

1371+
#[napi]
1372+
pub fn hex_spend_bundle_to_coin_spends(hex: String) -> napi::Result<Vec<CoinSpend>> {
1373+
let bytes = hex::decode(hex).map_err(js::err)?;
1374+
let spend_bundle = RustSpendBundle::from_bytes(&bytes).map_err(js::err)?;
1375+
spend_bundle
1376+
.coin_spends
1377+
.into_iter()
1378+
.map(|cs| cs.to_js())
1379+
.collect::<Result<Vec<CoinSpend>>>()
1380+
}
1381+
13711382
#[napi]
13721383
/// Computes the ID (name) of a coin.
13731384
///
@@ -1615,5 +1626,5 @@ pub fn simulator_new_program(pk: Buffer) -> napi::Result<Buffer> {
16151626
let pk = RustPublicKey::from_js(pk)?;
16161627
let program =
16171628
to_program([AggSigMe::new(pk, b"Hello, world!".to_vec().into())]).map_err(js::err)?;
1618-
Ok(program.to_js()?)
1629+
program.to_js()
16191630
}

0 commit comments

Comments
 (0)