0.0.1-beta-1 • Published 3 months ago

expo-symbol-sdk v0.0.1-beta-1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

This package is a fork of the symbol-sdk-crypto

Expo Symbol SDK

This library is a lightweight SDK extracted from the Symbol SDK’s use of Node.js’s crypto module. To avoid complex dependency resolutions on platforms like Web, Node.js, and React Native, this library serves as the base for SDKs tailored to each platform. This light version of the SDK offers the following features:

  • Creation and loading of private keys
  • Encryption and decryption of messages
  • Signing of transaction payloads with a private key

Installation

npm install symbol-sdk@3 expo-symbol-sdk

Usage

Create PrivateKey

import { Account, NetworkType } from "symbol-sdk-crypto";

const account = Account.generateNewAccount(NetworkType.TEST_NET);
console.log(account);

Signing a transaction created with symbol-sdk.

const account = Account.generateNewAccount(NetworkType.TEST_NET);

const generationHash = "49D6E1CE276A85B70EAFE52349AACCA389302E7A9754BCF1221E79494FC665A4";
const serializedTransactionPayload =
  "AE00000000000000000000000000000000000000000000000000000000000000" +
  "0000000000000000000000000000000000000000000000000000000000000000" +
  "0000000000000000000000000000000000000000000000000000000000000000" +
  "0000000000000000000000000000000000000000000000000000000000000001" +
  "985441F84300000000000003983E640900000098EC10797B167D59E419781125" +
  "EE36676AA61D9E4F90CDAF0E000000000000000048656C6C6F2053796D626F6C21";

const signedPayload = account.sign(serializedTransactionPayload, generationHash);
console.log(signedPayload);

Encryption and decryption of messages.

import { Account, NetworkType, EncryptMessage } from "symbol-sdk-crypto";

const bob = Account.generateNewAccount(NetworkType.TEST_NET);
const ben = Account.generateNewAccount(NetworkType.TEST_NET);

// encrypt message
const message = EncryptMessage.encrypt(bob.privateKey, ben.publicKey, "hello");
console.log(message);

// decrypto message
const decrypt = EncryptMessage.decrypt(ben.privateKey, bob.publicKey, message);
console.log(decrypt);