Skip to content

Instantly share code, notes, and snippets.

View xhliu's full-sized avatar

xhliu xhliu

View GitHub Profile
@xhliu
xhliu / scriptEval.js
Last active December 2, 2019 23:09
Sample code to evaluate bitcoin script using Bitcoin SV Library (bsv) https://docs.moneybutton.com/docs/bsv-overview.html
let bsv = require('bsv')
const slockStr = "OP_2 OP_EQUAL"
const slock = bsv.Script.fromASM(slockStr)
console.log("\nLocking script loaded\n")
const sunlockStr = "OP_2"
const sunlock = bsv.Script.fromASM(sunlockStr)
console.log("\nUnlocking script loaded\n")
@xhliu
xhliu / escrow_zkp.js
Last active January 25, 2023 10:49
escrow w/ zkp
// require node 10 and Rust to run
// https://github.com/ZenGo-X/dlog-verifiable-enc
var ve = require('dlog-verifiable-enc').ve;
var assert = require('assert');
var { bsv, toHex, buildContractClass, Ripemd160, signTx, PubKey, Sig } = require('scryptlib');
const G = bsv.crypto.Point.getG()
const N = bsv.crypto.Point.getN()
const BN = bsv.crypto.BN
const { inputIndex, inputSatoshis, newTx, loadDesc } = require('./helper');
import { Signer, SignatureRequest, SignatureResponse, SignTransactionOptions } from "../abstract-signer";
import { Provider, UtxoQueryOptions } from "../abstract-provider";
import { AddressesOption, AddressOption, Network, UTXO } from "../types";
import { bsv } from "scryptlib/dist";
import {parseAddresses} from "../utils";
const DEFAULT_SIGHASH_TYPE = bsv.crypto.Signature.ALL;
/**
import { Networks, PublicKey, Transaction } from "bsv";
import { bsv } from "scryptlib";
import { Provider } from "../abstract-provider";
import { Signer, SignTransactionOptions, SignatureRequest, SignatureResponse } from "../abstract-signer";
import { DefaultProvider } from "../providers/default-provider";
import { AddressOption} from "../types";
import { parseAddresses } from "../utils"
// see https://doc.sensilet.com/guide/sensilet-api.html
interface SensiletWalletAPI {
import React from 'react';
import { sendMessageAndWaitForResponse } from '../utils/globals';
import { connect } from '../store/portSlice';
import store, { RootState } from '../store/store';
import { TAALSigner } from '../signers/TAALSigner';
import {
bsv,
DefaultProvider,
DefaultProviderOption,
} from 'scrypt-ts'
@xhliu
xhliu / bchtokenprotocols
Created May 8, 2023 20:49 — forked from HostFat/bchtokenprotocols
Bitcoin Cash Token Protocols
They are NOT in order of importance and/or quality, so you should give a look to all of them.
(continuously updated)
It is likely that there will be 10 different token protocols this year (2018)
"Currently", even those now reported here, they are still in full development.
Wormhole (based on Omni)
- Website: http://wormhole.cash - you can change the language on upper right
- Spec: http://wormhole.cash/whcwhitepaper.pdf (in Chinese language)
- Spec ENG part 1: https://www.yours.org/content/bch-smart-contract-is-coming----wormhole-protocol-proposed-by-bitmain-1debc785b3f8
@xhliu
xhliu / irs.sol
Last active November 3, 2023 18:32
irs
//https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/ownership/Ownable.sol
import 'openzeppelin-solidity/contracts/ownership/Ownable.sol';
import 'openzeppelin-solidity/contracts/math/SafeMath.sol';
pragma solidity ^0.4.18;
contract IntSwap is Ownable{
using SafeMath for uint256;
event Deposited(address indexed payee, uint256 amount, uint256 timestamp);
@xhliu
xhliu / deriveAddress.js
Last active January 9, 2024 08:52
A simple demo for derived bitcoin addresses
// Copyright (c) 2020 Xiaohui Liu.
// Use of this source code is governed by a MIT-style license.
// This is an implementation of https://craigwright.net/blog/bitcoin-blockchain-tech/offline-addressing
// For more info, also see Episode 4 of Bitcoin Class with Satoshi: Extended Address https://youtu.be/rezvcJ4j-7U
const bsv = require('bsv');
const BN = bsv.crypto.BN
const Hash = bsv.crypto.Hash
const G = bsv.crypto.Point.getG()
const N = bsv.crypto.Point.getN()
@xhliu
xhliu / OP_MOD_U30_U15_x2.asm
Created February 10, 2024 00:21 — forked from cf/OP_MOD_U30_U15_x2.asm
OP_MOD for Bitcoin Mainnet
/*
compute x % y given: q_lo = floor(x/y)&0x7fff, q_hi = floor(x/y)>>15, x_lo = x&0x7fff, x_hi = x>>15, y_lo = y&0x7ff, y_hi = y>>15
<q_hi>
<q_lo>
<x_hi>
<x_lo>
@xhliu
xhliu / unknownPrivkeySig.ts
Last active February 13, 2024 18:56 — forked from msinkec/unknownPrivkeySig.ts
Create Sig and PubKey with unknown PrivKey
import { bsv } from 'scrypt-ts'
async function main() {
const msg = 'I am Satoshi'
const hBuff = bsv.crypto.Hash.sha256(Buffer.from(msg))
const h = bsv.crypto.BN.fromBuffer(hBuff)
const G = bsv.crypto.Point.getG()
const n = bsv.crypto.Point.getN()