Skip to content

Silent payment basic scheme #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"blech32": "^1.0.1",
"bs58check": "^2.0.0",
"create-hash": "^1.2.0",
"ecpair": "^2.1.0",
"slip77": "^0.2.0",
"typeforce": "^1.11.3",
"varuint-bitcoin": "^1.1.2"
Expand All @@ -78,6 +77,7 @@
"bn.js": "^4.11.8",
"bs58": "^4.0.0",
"dhttp": "^3.0.0",
"ecpair": "^2.1.0",
"hoodwink": "^2.0.0",
"minimaldata": "^1.0.2",
"mocha": "^10.1.0",
Expand All @@ -88,7 +88,7 @@
"randombytes": "^2.1.0",
"regtest-client": "0.2.0",
"rimraf": "^2.6.3",
"tiny-secp256k1": "^2.2.1",
"tiny-secp256k1": "^2.2.3",
"ts-node": "^10.9.1",
"tslint": "^6.1.3",
"typescript": "^4.4.4"
Expand Down
2 changes: 1 addition & 1 deletion src/bip341.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function taprootSignScriptStack(ecc) {
return (internalPublicKey, leaf, treeRootHash, path) => {
const { parity } = tweakPublicKey(internalPublicKey, treeRootHash, ecc);
const parityBit = Buffer.of(
leaf.version || exports.LEAF_VERSION_TAPSCRIPT + parity,
(leaf.version || exports.LEAF_VERSION_TAPSCRIPT) + parity,
);
const control = Buffer.concat([
parityBit,
Expand Down
18 changes: 9 additions & 9 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as address from './address';
import * as crypto from './crypto';
import * as networks from './networks';
import * as payments from './payments';
import * as script from './script';
import * as issuance from './issuance';
import * as bip341 from './bip341';
import * as confidential from './confidential';
export { address, confidential, crypto, networks, payments, script, issuance, bip341, };
export * as address from './address';
export * as crypto from './crypto';
export * as networks from './networks';
export * as payments from './payments';
export * as script from './script';
export * as issuance from './issuance';
export * as bip341 from './bip341';
export * as confidential from './confidential';
export * as silentpayment from './silentpayment';
export { OPS as opcodes } from './ops';
export { Input as TxInput, Output as TxOutput, Transaction, } from './transaction';
export * from './asset';
Expand Down
28 changes: 11 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,25 @@ var __exportStar =
Object.defineProperty(exports, '__esModule', { value: true });
exports.Transaction =
exports.opcodes =
exports.silentpayment =
exports.confidential =
exports.bip341 =
exports.issuance =
exports.script =
exports.payments =
exports.networks =
exports.crypto =
exports.confidential =
exports.address =
void 0;
const address = __importStar(require('./address'));
exports.address = address;
const crypto = __importStar(require('./crypto'));
exports.crypto = crypto;
const networks = __importStar(require('./networks'));
exports.networks = networks;
const payments = __importStar(require('./payments'));
exports.payments = payments;
const script = __importStar(require('./script'));
exports.script = script;
const issuance = __importStar(require('./issuance'));
exports.issuance = issuance;
const bip341 = __importStar(require('./bip341'));
exports.bip341 = bip341;
const confidential = __importStar(require('./confidential'));
exports.confidential = confidential;
exports.address = __importStar(require('./address'));
exports.crypto = __importStar(require('./crypto'));
exports.networks = __importStar(require('./networks'));
exports.payments = __importStar(require('./payments'));
exports.script = __importStar(require('./script'));
exports.issuance = __importStar(require('./issuance'));
exports.bip341 = __importStar(require('./bip341'));
exports.confidential = __importStar(require('./confidential'));
exports.silentpayment = __importStar(require('./silentpayment'));
var ops_1 = require('./ops');
Object.defineProperty(exports, 'opcodes', {
enumerable: true,
Expand Down
53 changes: 53 additions & 0 deletions src/silentpayment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/// <reference types="node" />
import { bip341 } from '.';
export declare type Target = {
silentPaymentAddress: string;
value: number;
asset: string;
};
export declare type Output = {
scriptPubKey: string;
value: number;
asset: string;
};
export interface TinySecp256k1Interface extends bip341.BIP341Secp256k1Interface {
privateMultiply: (key: Uint8Array, tweak: Uint8Array) => Uint8Array;
pointMultiply: (point: Uint8Array, tweak: Uint8Array) => Uint8Array | null;
pointAdd: (point1: Uint8Array, point2: Uint8Array) => Uint8Array | null;
pointFromScalar: (key: Uint8Array) => Uint8Array | null;
privateAdd: (key: Uint8Array, tweak: Uint8Array) => Uint8Array | null;
privateNegate: (key: Uint8Array) => Uint8Array;
ecdh: (pubkey: Uint8Array, privkey: Uint8Array) => Uint8Array;
}
export declare class SilentPaymentAddress {
readonly spendPublicKey: Buffer;
readonly scanPublicKey: Buffer;
constructor(spendPublicKey: Buffer, scanPublicKey: Buffer);
static decode(str: string): SilentPaymentAddress;
encode(): string;
}
export declare class SilentPayment {
private ecc;
constructor(ecc: TinySecp256k1Interface);
/**
* create the transaction outputs sending outpoints identified by *outpointHash* to the *targets*
* @param inputsOutpointsHash hash of the input outpoints sent to the targets
* @param sumInputsPrivKeys sum of input private keys
* @param targets silent payment addresses receiving value/asset pair
* @returns a list of "silent-payment" taproot outputs
*/
pay(inputsOutpointsHash: Buffer, sumInputsPrivKeys: Buffer, targets: Target[]): Output[];
sumSecretKeys(outpointKeys: {
key: Buffer;
isTaproot?: boolean;
}[]): Buffer;
sumPublicKeys(keys: Buffer[]): Buffer;
makeSharedSecret(inputsOutpointsHash: Buffer, inputPubKey: Buffer, scanSecretKey: Buffer): Buffer;
makePublicKey(spendPubKey: Buffer, index: number, ecdhSharedSecret: Buffer): Buffer;
makeSecretKey(spendPrivKey: Buffer, index: number, ecdhSharedSecret: Buffer): Buffer;
}
export declare function ser32(i: number): Buffer;
export declare function outpointsHash(parameters: {
txid: string;
vout: number;
}[]): Buffer;
Loading