Socket
Socket
Sign inDemoInstall

@jm9k/nervos-lumos-sign-message

Package Overview
Dependencies
21
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @jm9k/nervos-lumos-sign-message

A function for Nervos' Lumos framework to sign a message using an Secp256k1 private key.


Version published
Maintainers
1
Created

Readme

Source

Nervos Lumos Sign Message

A function for Nervos' Lumos framework to sign a message using an Secp256k1 private key.

Installation

In your Node.js project directory type:

npm i @jm9k/nervos-lumos-sign-message

Usage Example

const { createTransactionFromSkeleton, generateAddress, sealTransaction, TransactionSkeleton } = require("@ckb-lumos/helpers");
const { Indexer } = require("@ckb-lumos/indexer");
const { initializeConfig } = require("@ckb-lumos/config-manager");
const { Reader, RPC } = require("ckb-js-toolkit");
const { secp256k1Blake160 } = require("@ckb-lumos/common-scripts");
const { signMessage } = require("@jm9k/nervos-lumos-sign-message");

const nodeUrl = "http://127.0.0.1:8114/";
const privateKey = "0xd00c06bfd800d27397002dca6fb0993d5ba6399b4238b2f29ee9deb97593d2bc";
const lockArg = "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7";
const script =
{
	code_hash: "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
	hash_type: "type",
	args: lockArg
};

async function main()
{
	initializeConfig();

	const indexer = new Indexer(nodeUrl, "./indexed-data");
	indexer.startForever();

	const address = generateAddress(script);

	let skeleton = TransactionSkeleton({ cellProvider: indexer });
	skeleton = await secp256k1Blake160.payFee(skeleton, address, 1000000n);
	skeleton = secp256k1Blake160.prepareSigningEntries(skeleton);

	const signingEntries = skeleton.get("signingEntries").toArray();
	const signature = signMessage(privateKey, signingEntries[0].message);
	const tx = sealTransaction(skeleton, [signature]);

	const rpc = new RPC(nodeUrl);
	const res = await rpc.send_transaction(tx);
	console.log(res);
}
main();

Keywords

FAQs

Last updated on 15 Nov 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc