0.0.65 • Published 2 months ago

@smontero/smartvaults-js-client v0.0.65

Weekly downloads
-
License
ISC
Repository
-
Last release
2 months ago

Install dependencies

npm install

Build

npx tsc

Usage examples

Install

npm install @smontero/smartvaults-js-client @smontero/smartvaults-wasm @smontero/nostr-ual --save

Import modules

import { NostrClient, SmartVaults, Contact } from '@smontero/smartvaults-js-client';
import { DirectPrivateKeyAuthenticator } from '@smontero/nostr-ual'
import {
  Wallet,
  miniscript_to_descriptor as miniScriptToDescriptor,
  can_finalize_psbt as canFinalizePsbt,
  get_trx_id as getTrxIdWasm,
  get_fee as getFeeWasm,
  MiniscriptBuilder,
  get_psbt_utxos as getPsbtUtxos,
  descriptor_to_miniscript as descriptorToMiniscript
} from '@smontero/smartvaults-wasm'
import { generatePrivateKey } from 'nostr-tools'

Initializing SmartVaults

Parameters for Initialization:

  1. authenticator: An instance of an Authenticator
  2. bitcoinUtil: Utility functions related to Bitcoin transactions
  3. nostrClient: An instance of NostrClient for interacting with Nostr relays
const authenticator = new DirectPrivateKeyAuthenticator(generatePrivateKey())
const bitcoinUtil = {
        walletSyncTimeGap: 3, 
        toDescriptor: miniScriptToDescriptor,
        createWallet: (descriptor) => {
          return new Wallet(
            descriptor,
            'https://mempool.space/testnet/api',
            'testnet',
             15
          )
        },
        canFinalizePsbt: (psbts) => canFinalizePsbt(psbts),
        getTrxId: (trx) => getTrxIdWasm(trx),
        getFee: (psbt) => getFeeWasm(psbt),
        getPsbtUtxos: (psbt) => getPsbtUtxos(psbt),
        toMiniscript: (descriptor) => descriptorToMiniscript(descriptor)
}
const nostrClient = new NostrClient(['wss://test.relay.report'])
const smartVaults = new SmartVaults ({authenticator, bitcoinUtil, nostrClient})

Example: Set profile and Contacts

// Define the metadata object
const metadata = { name:'Bob', about:'Learning about Smart Vaults!'}
// Set profile
await smartVaults.setProfile(metadata)
const myPublicKey = authenticator.getPublicKey()
// Fetch profile
const myProfile = await smartVaults.getProfile(myPublicKey)
// Create another account to add as contact
const otherAuthenticator = new DirectPrivateKeyAuthenticator(generatePrivateKey())
const contactPubKey = otherAuthenticator.getPublicKey()
const contact = new Contact({publicKey: contactPubKey})
// Add contact
await smartVaults.upsertContacts(contact);
// Fetch contacts
const contacts = await smartVaults.getContacts()
// Fetch contacts including their metadata ( profile )
const contactsProfiles = await smartVaults.getContactProfiles()

Example: Create an 2-of-2 Multisig Vault

// For this example lets assume that we have created an account using one of the Smart Vaults apps ( iOs, Android or Desktop ).

// Get your Signers
const mySigners = await smartVaults.getOwnedSigners()
// For simplicity lets assume that we only have one signer
const mySigner = mySigners[0]
// Get your signer's Key
const mySignerKey = mySigner.key
// Get co-Signer's Key
const coSigner = await smartVaults.getSharedSigners()
const coSignerKey = coSigner[0].key
const keys = [mySignerKey, coSignerKey]
// Define the threshold
const threshold = 2
// Create the multisig miniscript
const miniscript = MiniscriptBuilder.multisig({threshold, keys})
// Define the other parameters
const name = 'My First Vault'
const description = "2 of 2 Multisig"
const nostrPublicKeys = [myPublicKey, contactPubKey]

// Create the vault
await smartVaults.savePolicy({ name, description, miniscript, nostrPublicKeys })
                                                    
0.0.64

2 months ago

0.0.65

2 months ago

0.0.63

2 months ago

0.0.62

2 months ago

0.0.61

2 months ago

0.0.60

2 months ago

0.0.59

3 months ago

0.0.58

3 months ago

0.0.57

3 months ago

0.0.55

3 months ago

0.0.54

4 months ago

0.0.53

4 months ago

0.0.52

4 months ago

0.0.51

4 months ago

0.0.50

4 months ago

0.0.49

4 months ago

0.0.48

5 months ago

0.0.46

5 months ago

0.0.47

5 months ago

0.0.45

5 months ago

0.0.44

6 months ago

0.0.43

6 months ago

0.0.42

6 months ago

0.0.41

6 months ago

0.0.40

6 months ago

0.0.39

6 months ago

0.0.38

7 months ago

0.0.37

7 months ago

0.0.36

7 months ago

0.0.35

7 months ago

0.0.34

8 months ago

0.0.33

8 months ago

0.0.32

8 months ago

0.0.30

8 months ago

0.0.29

8 months ago