Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bitauth/libauth

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bitauth/libauth - npm Package Compare versions

Comparing version 2.0.0-alpha.2 to 2.0.0-alpha.3

build/lib/crypto/combinations.d.ts

4

build/lib/address/base58-address.js

@@ -1,2 +0,2 @@

import { sha256 as internalSha256 } from '../crypto/default-crypto-instances.js';
import { hash256, sha256 as internalSha256 } from '../crypto/crypto.js';
import { base58ToBin, BaseConversionError, binToBase58, flattenBinArray, } from '../format/format.js';

@@ -100,3 +100,3 @@ /**

const content = Uint8Array.from([version, ...payload]);
const checksum = sha256.hash(sha256.hash(content)).slice(0, checksumBytes);
const checksum = hash256(content, sha256).slice(0, checksumBytes);
const bin = flattenBinArray([content, checksum]);

@@ -103,0 +103,0 @@ return binToBase58(bin);

@@ -101,3 +101,3 @@ import type { Immutable } from '../lib';

*/
export declare const decodeBech32: (validBech32: string) => (0 | 1 | 4 | 2 | 3 | 15 | 6 | 16 | 8 | 18 | 12 | 10 | 31 | 7 | 9 | 5 | 20 | 11 | 13 | 14 | 17 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30)[];
export declare const decodeBech32: (validBech32: string) => (0 | 2 | 1 | 22 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 31 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30)[];
/**

@@ -104,0 +104,0 @@ * Validate that a string uses only characters from the bech32 character set.

@@ -35,8 +35,19 @@ import type { Base58AddressNetwork, CashAddressNetworkPrefix, Sha256 } from '../lib';

*/
p2sh20 = "P2SH20",
p2sh20 = "P2SH20"
}
/**
* An object representing the contents of an address of a known address type.
* This can be used to encode an address or its locking bytecode.
*/
export interface KnownAddressTypeContents {
type: `${AddressType}`;
payload: Uint8Array;
}
export interface UnknownAddressTypeContents {
/**
* This `AddressType` represents an address using an unknown or uncommon
* This address type represents an address using an unknown or uncommon
* locking bytecode pattern for which no standardized address formats exist.
*/
unknown = "unknown"
type: 'unknown';
payload: Uint8Array;
}

@@ -47,8 +58,5 @@ /**

*
* See `lockingBytecodeToAddressContents` for details.
* See {@link lockingBytecodeToAddressContents} for details.
*/
export interface AddressContents {
type: AddressType;
payload: Uint8Array;
}
export declare type AddressContents = KnownAddressTypeContents | UnknownAddressTypeContents;
export declare const isPayToPublicKeyUncompressed: (lockingBytecode: Uint8Array) => boolean;

@@ -82,11 +90,43 @@ export declare const isPayToPublicKeyCompressed: (lockingBytecode: Uint8Array) => boolean;

/**
* Get the locking bytecode for a valid {@link AddressContents}. See
* Given the 20-byte {@link hash160} of a compressed public key, return a P2PKH
* locking bytecode:
* `OP_DUP OP_HASH160 OP_PUSHBYTES_20 publicKeyHash OP_EQUALVERIFY OP_CHECKSIG`.
*
* This method does not validate `publicKeyHash` in any way; inputs of incorrect
* lengths will produce incorrect results.
*
* @param publicKeyHash - the 20-byte hash of the compressed public key
* @returns
*/
export declare const encodeLockingBytecodeP2pkh: (publicKeyHash: Uint8Array) => Uint8Array;
/**
* Given the 20-byte {@link hash160} of a P2SH20 redeem bytecode, encode a
* P2SH20 locking bytecode:
* `OP_HASH160 OP_PUSHBYTES_20 redeemBytecodeHash OP_EQUAL`.
*
* This method does not validate `p2sh20Hash` in any way; inputs of incorrect
* lengths will produce incorrect results.
*
* @param p2sh20Hash - the 20-byte, p2sh20 redeem bytecode hash
* @returns
*/
export declare const encodeLockingBytecodeP2sh20: (p2sh20Hash: Uint8Array) => Uint8Array;
/**
* Given a 33-byte compressed or 65-byte uncompressed public key, encode a P2PK
* locking bytecode: `OP_PUSHBYTES_33 publicKey OP_CHECKSIG` or
* `OP_PUSHBYTES_65 publicKey OP_CHECKSIG`.
*
* This method does not validate `publicKey` in any way; inputs of incorrect
* lengths will produce incorrect results.
*
* @param publicKey - the 33-byte or 65-byte public key
*/
export declare const encodeLockingBytecodeP2pk: (publicKey: Uint8Array) => Uint8Array;
/**
* Get the locking bytecode for a {@link KnownAddressTypeContents}. See
* {@link lockingBytecodeToAddressContents} for details.
*
* For {@link AddressContents} of `type` {@link AddressType.unknown}, this
* method returns the `payload` without modification.
*
* @param addressContents - the `AddressContents` to encode
*/
export declare const addressContentsToLockingBytecode: (addressContents: AddressContents) => Uint8Array;
export declare const addressContentsToLockingBytecode: ({ payload, type, }: KnownAddressTypeContents) => Uint8Array;
/**

@@ -93,0 +133,0 @@ * Encode a locking bytecode as a CashAddress given a network prefix.

@@ -1,2 +0,2 @@

import { sha256 as internalSha256 } from '../crypto/default-crypto-instances.js';
import { sha256 as internalSha256 } from '../crypto/crypto.js';
import { Base58AddressFormatVersion, decodeBase58Address, encodeBase58AddressFormat, } from './base58-address.js';

@@ -39,7 +39,2 @@ import { CashAddressType, decodeCashAddress, encodeCashAddress, } from './cash-address.js';

AddressType["p2sh20"] = "P2SH20";
/**
* This `AddressType` represents an address using an unknown or uncommon
* locking bytecode pattern for which no standardized address formats exist.
*/
AddressType["unknown"] = "unknown";
})(AddressType || (AddressType = {}));

@@ -112,47 +107,78 @@ export const isPayToPublicKeyUncompressed = (lockingBytecode) => lockingBytecode.length === 67 /* length */ &&

}
return { payload: bytecode.slice(), type: AddressType.unknown };
return { payload: bytecode.slice(), type: 'unknown' };
};
/**
* Get the locking bytecode for a valid {@link AddressContents}. See
* Given the 20-byte {@link hash160} of a compressed public key, return a P2PKH
* locking bytecode:
* `OP_DUP OP_HASH160 OP_PUSHBYTES_20 publicKeyHash OP_EQUALVERIFY OP_CHECKSIG`.
*
* This method does not validate `publicKeyHash` in any way; inputs of incorrect
* lengths will produce incorrect results.
*
* @param publicKeyHash - the 20-byte hash of the compressed public key
* @returns
*/
export const encodeLockingBytecodeP2pkh = (publicKeyHash) => Uint8Array.from([
118 /* OP_DUP */,
169 /* OP_HASH160 */,
20 /* OP_PUSHBYTES_20 */,
...publicKeyHash,
136 /* OP_EQUALVERIFY */,
172 /* OP_CHECKSIG */,
]);
/**
* Given the 20-byte {@link hash160} of a P2SH20 redeem bytecode, encode a
* P2SH20 locking bytecode:
* `OP_HASH160 OP_PUSHBYTES_20 redeemBytecodeHash OP_EQUAL`.
*
* This method does not validate `p2sh20Hash` in any way; inputs of incorrect
* lengths will produce incorrect results.
*
* @param p2sh20Hash - the 20-byte, p2sh20 redeem bytecode hash
* @returns
*/
export const encodeLockingBytecodeP2sh20 = (p2sh20Hash) => Uint8Array.from([
169 /* OP_HASH160 */,
20 /* OP_PUSHBYTES_20 */,
...p2sh20Hash,
135 /* OP_EQUAL */,
]);
/**
* Given a 33-byte compressed or 65-byte uncompressed public key, encode a P2PK
* locking bytecode: `OP_PUSHBYTES_33 publicKey OP_CHECKSIG` or
* `OP_PUSHBYTES_65 publicKey OP_CHECKSIG`.
*
* This method does not validate `publicKey` in any way; inputs of incorrect
* lengths will produce incorrect results.
*
* @param publicKey - the 33-byte or 65-byte public key
*/
export const encodeLockingBytecodeP2pk = (publicKey) => publicKey.length === 33 /* compressedPublicKeyLength */
? Uint8Array.from([
33 /* OP_PUSHBYTES_33 */,
...publicKey,
172 /* OP_CHECKSIG */,
])
: Uint8Array.from([
65 /* OP_PUSHBYTES_65 */,
...publicKey,
172 /* OP_CHECKSIG */,
]);
/**
* Get the locking bytecode for a {@link KnownAddressTypeContents}. See
* {@link lockingBytecodeToAddressContents} for details.
*
* For {@link AddressContents} of `type` {@link AddressType.unknown}, this
* method returns the `payload` without modification.
*
* @param addressContents - the `AddressContents` to encode
*/
export const addressContentsToLockingBytecode = (addressContents) => {
if (addressContents.type === AddressType.p2pkh) {
return Uint8Array.from([
118 /* OP_DUP */,
169 /* OP_HASH160 */,
20 /* OP_PUSHBYTES_20 */,
...addressContents.payload,
136 /* OP_EQUALVERIFY */,
172 /* OP_CHECKSIG */,
]);
export const addressContentsToLockingBytecode = ({ payload, type, }) => {
if (type === AddressType.p2pkh) {
return encodeLockingBytecodeP2pkh(payload);
}
if (addressContents.type === AddressType.p2sh20) {
return Uint8Array.from([
169 /* OP_HASH160 */,
20 /* OP_PUSHBYTES_20 */,
...addressContents.payload,
135 /* OP_EQUAL */,
]);
if (type === AddressType.p2sh20) {
return encodeLockingBytecodeP2sh20(payload);
}
if (addressContents.type === AddressType.p2pk) {
const compressedPublicKeyLength = 33;
return addressContents.payload.length === compressedPublicKeyLength
? Uint8Array.from([
33 /* OP_PUSHBYTES_33 */,
...addressContents.payload,
172 /* OP_CHECKSIG */,
])
: Uint8Array.from([
65 /* OP_PUSHBYTES_65 */,
...addressContents.payload,
172 /* OP_CHECKSIG */,
]);
if (type === AddressType.p2pk) {
return encodeLockingBytecodeP2pk(payload);
}
return addressContents.payload;
return undefined;
};

@@ -159,0 +185,0 @@ /**

@@ -1,2 +0,2 @@

import { ripemd160 as internalRipemd160, secp256k1 as internalSecp256k1, sha256 as internalSha256, sha512 as internalSha512, } from '../../crypto/default-crypto-instances.js';
import { hash256, ripemd160 as internalRipemd160, secp256k1 as internalSecp256k1, sha256 as internalSha256, sha512 as internalSha512, } from '../../crypto/crypto.js';
import { createAuthenticationVirtualMachine, createInstructionSetBCH, generateBytecodeMap, generateSigningSerializationBCH, OpcodesBCH2022, SigningSerializationFlag, } from '../../vm/vm.js';

@@ -93,3 +93,3 @@ import { attemptCompilerOperations, compilerOperationAttemptBytecodeResolution, compilerOperationHelperCompileScript, compilerOperationHelperDeriveHdKeyPrivate, compilerOperationHelperGenerateCoveredBytecode, compilerOperationRequires, } from '../compiler-operation-helpers.js';

const serialization = generateSigningSerializationBCH(compilationContext, { coveredBytecode, signingSerializationType }, sha256);
const digest = sha256.hash(sha256.hash(serialization));
const digest = hash256(serialization, sha256);
const bitcoinEncodedSignature = Uint8Array.from([

@@ -96,0 +96,0 @@ ...sign(privateKey, digest),

@@ -1,2 +0,2 @@

import { ripemd160 as internalRipemd160, secp256k1 as internalSecp256k1, sha256 as internalSha256, sha512 as internalSha512, } from '../crypto/default-crypto-instances.js';
import { ripemd160 as internalRipemd160, secp256k1 as internalSecp256k1, sha256 as internalSha256, sha512 as internalSha512, } from '../crypto/crypto.js';
import { compileScript } from '../language/language.js';

@@ -3,0 +3,0 @@ import { generateBytecodeMap, Opcodes, OpcodesBCH, OpcodesBTC, } from '../vm/vm.js';

@@ -6,3 +6,3 @@ import type { CashAddressNetworkPrefix } from '../lib.js';

*/
export declare const hdKeyToP2pkhLockingBytecode: ({ addressIndex, hdKey, }: {
export declare const hdPrivateKeyToP2pkhLockingBytecode: ({ addressIndex, hdKey, }: {
/**

@@ -25,3 +25,3 @@ * An encoded HD private key, e.g.

*/
export declare const hdKeyToP2pkhAddress: <Prefix extends string = CashAddressNetworkPrefix>({ addressIndex, hdKey, prefix, }: {
export declare const hdPrivateKeyToP2pkhAddress: <Prefix extends string = CashAddressNetworkPrefix>({ addressIndex, hdKey, prefix, }: {
/**

@@ -28,0 +28,0 @@ * An encoded HD private key, e.g.

@@ -9,3 +9,3 @@ import { lockingBytecodeToCashAddress } from '../address/address.js';

*/
export const hdKeyToP2pkhLockingBytecode = ({ addressIndex, hdKey, }) => {
export const hdPrivateKeyToP2pkhLockingBytecode = ({ addressIndex, hdKey, }) => {
const compiler = authenticationTemplateToCompilerBCH(importAuthenticationTemplate(authenticationTemplateP2pkh));

@@ -22,3 +22,3 @@ const lockingBytecode = compiler.generateBytecode({

*/
export const hdKeyToP2pkhAddress = ({ addressIndex, hdKey, prefix = 'bitcoincash', }) => lockingBytecodeToCashAddress(hdKeyToP2pkhLockingBytecode({ addressIndex, hdKey }), prefix);
export const hdPrivateKeyToP2pkhAddress = ({ addressIndex, hdKey, prefix = 'bitcoincash', }) => lockingBytecodeToCashAddress(hdPrivateKeyToP2pkhLockingBytecode({ addressIndex, hdKey }), prefix);
//# sourceMappingURL=p2pkh-utils.js.map

@@ -0,1 +1,2 @@

export * from './combinations.js';
export * from './default-crypto-instances.js';

@@ -2,0 +3,0 @@ export * from './hmac.js';

@@ -0,1 +1,2 @@

export * from './combinations.js';
export * from './default-crypto-instances.js';

@@ -2,0 +3,0 @@ export * from './hmac.js';

/* eslint-disable max-lines */
import { ripemd160 as internalRipemd160, secp256k1 as internalSecp256k1, sha256 as internalSha256, sha512 as internalSha512, } from '../crypto/default-crypto-instances.js';
import { hmacSha512 } from '../crypto/hmac.js';
import { hmacSha512, ripemd160 as internalRipemd160, secp256k1 as internalSecp256k1, sha256 as internalSha256, sha512 as internalSha512, } from '../crypto/crypto.js';
import { base58ToBin, BaseConversionError, bigIntToBinUint256BEClamped, binToBase58, binToBigIntUint256BE, flattenBinArray, numberToBinUint32BE, } from '../format/format.js';

@@ -5,0 +4,0 @@ import { validateSecp256k1PrivateKey } from './key-utils.js';

import { Base58AddressFormatVersion, decodeBase58AddressFormat, encodeBase58AddressFormat, } from '../address/address.js';
import { sha256 as internalSha256 } from '../crypto/default-crypto-instances.js';
import { sha256 as internalSha256 } from '../crypto/crypto.js';
export var WalletImportFormatError;

@@ -4,0 +4,0 @@ (function (WalletImportFormatError) {

@@ -1,2 +0,2 @@

import { sha256 as internalSha256 } from '../crypto/default-crypto-instances.js';
import { hash256, sha256 as internalSha256 } from '../crypto/crypto.js';
import { bigIntToVarInt, binToHex, binToNumberUint32LE, flattenBinArray, numberToBinUint32LE, varIntToBigInt, } from '../format/format.js';

@@ -247,3 +247,3 @@ /**

*/
export const hashTransactionP2pOrder = (transaction, sha256 = internalSha256) => sha256.hash(sha256.hash(transaction));
export const hashTransactionP2pOrder = (transaction, sha256 = internalSha256) => hash256(transaction, sha256);
/**

@@ -250,0 +250,0 @@ * Compute a transaction hash (A.K.A. "transaction ID" or "TXID") from an

import { isPayToScriptHash20 } from '../../../../address/address.js';
import { ripemd160 as internalRipemd160, secp256k1 as internalSecp256k1, sha1 as internalSha1, sha256 as internalSha256, } from '../../../../crypto/default-crypto-instances.js';
import { ripemd160 as internalRipemd160, secp256k1 as internalSecp256k1, sha1 as internalSha1, sha256 as internalSha256, } from '../../../../crypto/crypto.js';
import { encodeTransactionBCH } from '../../../../message/message.js';

@@ -4,0 +4,0 @@ import { applyError, AuthenticationErrorCommon, authenticationInstructionsAreMalformed, cloneAuthenticationProgramStateBCH, cloneStack, conditionallyEvaluate, ConsensusBCH, createAuthenticationProgramStateCommon, decodeAuthenticationInstructions, disabledOperation, incrementOperationCount, isArbitraryDataOutput, isPushOnly, isStandardOutputBytecode, isWitnessProgram, mapOverOperations, op0NotEqual, op1Add, op1Sub, op2Drop, op2Dup, op2Over, op2Rot, op2Swap, op3Dup, opAbs, opActiveBytecode, opAdd, opAnd, opBin2Num, opBoolAnd, opBoolOr, opCat, opCheckDataSig, opCheckDataSigVerify, opCheckLockTimeVerify, opCheckMultiSig, opCheckMultiSigVerify, opCheckSequenceVerify, opCheckSig, opCheckSigVerify, opCodeSeparator, opDepth, opDiv, opDrop, opDup, opElse, opEndIf, opEqual, opEqualVerify, opFromAltStack, opGreaterThan, opGreaterThanOrEqual, opHash160, opHash256, opIf, opIfDup, opInputBytecode, opInputIndex, opInputSequenceNumber, opLessThan, opLessThanOrEqual, opMax, opMin, opMod, opMul, opNegate, opNip, opNop, opNopDisallowed, opNot, opNotIf, opNum2Bin, opNumEqual, opNumEqualVerify, opNumNotEqual, opOr, opOutpointIndex, opOutpointTxHash, opOutputBytecode, opOutputValue, opOver, opPick, opReturn, opReverseBytes, opRipemd160, opRoll, opRot, opSha1, opSha256, opSize, opSplit, opSub, opSwap, opToAltStack, opTuck, opTxInputCount, opTxLocktime, opTxOutputCount, opTxVersion, opUtxoBytecode, opUtxoValue, opVerify, opWithin, opXor, pushNumberOperation, pushOperation, reservedOperation, stackItemIsTruthy, undefinedOperation, } from '../../common/common.js';

@@ -1,2 +0,2 @@

import { ripemd160 as internalRipemd160, secp256k1 as internalSecp256k1, sha1 as internalSha1, sha256 as internalSha256, } from '../../../crypto/default-crypto-instances.js';
import { hash256, ripemd160 as internalRipemd160, secp256k1 as internalSecp256k1, sha1 as internalSha1, sha256 as internalSha256, } from '../../../crypto/crypto.js';
import { combineOperations, pushToStack, useOneStackItem, useOneVmNumber, useThreeStackItems, useTwoStackItems, } from './combinators.js';

@@ -13,3 +13,3 @@ import { ConsensusCommon } from './consensus.js';

export const opHash160 = ({ ripemd160, sha256, } = { ripemd160: internalRipemd160, sha256: internalSha256 }) => (state) => useOneStackItem(state, (nextState, [value]) => pushToStack(nextState, ripemd160.hash(sha256.hash(value))));
export const opHash256 = ({ sha256, } = { sha256: internalSha256 }) => (state) => useOneStackItem(state, (nextState, [value]) => pushToStack(nextState, sha256.hash(sha256.hash(value))));
export const opHash256 = ({ sha256, } = { sha256: internalSha256 }) => (state) => useOneStackItem(state, (nextState, [value]) => pushToStack(nextState, hash256(value, sha256)));
export const opCodeSeparator = (state) => {

@@ -32,3 +32,3 @@ // eslint-disable-next-line functional/no-expression-statement, functional/immutable-data

const serialization = generateSigningSerializationBCH(state.program, { coveredBytecode, signingSerializationType }, sha256);
const digest = sha256.hash(sha256.hash(serialization));
const digest = hash256(serialization, sha256);
// eslint-disable-next-line functional/no-expression-statement, functional/immutable-data

@@ -101,3 +101,3 @@ state.signedMessages.push(serialization);

const serialization = generateSigningSerializationBCH(state.program, { coveredBytecode, signingSerializationType }, sha256);
const digest = sha256.hash(sha256.hash(serialization));
const digest = hash256(serialization, sha256);
// eslint-disable-next-line functional/no-expression-statement, functional/immutable-data

@@ -104,0 +104,0 @@ finalState.signedMessages.push(serialization);

@@ -1,2 +0,2 @@

import { sha256 as internalSha256 } from '../../../crypto/default-crypto-instances.js';
import { hash256, sha256 as internalSha256 } from '../../../crypto/crypto.js';
import { bigIntToVarInt, flattenBinArray, numberToBinUint32LE, } from '../../../format/format.js';

@@ -52,3 +52,3 @@ import { encodeTransactionInputSequenceNumbersForSigning, encodeTransactionOutpoints, encodeTransactionOutput, encodeTransactionOutputsForSigning, } from '../../../message/message.js';

? emptyHash()
: sha256.hash(sha256.hash(transactionOutpoints));
: hash256(transactionOutpoints, sha256);
/**

@@ -61,3 +61,3 @@ * Return the proper `hashSequence` value for a given a signing serialization

!shouldSerializeNoOutputs(signingSerializationType)
? sha256.hash(sha256.hash(transactionSequenceNumbers))
? hash256(transactionSequenceNumbers, sha256)
: emptyHash();

@@ -70,7 +70,7 @@ /**

!shouldSerializeNoOutputs(signingSerializationType)
? sha256.hash(sha256.hash(transactionOutputs))
? hash256(transactionOutputs, sha256)
: shouldSerializeCorrespondingOutput(signingSerializationType)
? correspondingOutput === undefined
? emptyHash()
: sha256.hash(sha256.hash(correspondingOutput))
: hash256(correspondingOutput, sha256)
: emptyHash();

@@ -77,0 +77,0 @@ /**

@@ -137,28 +137,28 @@ import type { AuthenticationTemplate, AuthenticationTemplateScenario } from '../lib';

export declare const vmbTestPartitionMasterTestList: (masterTestList: VmbTestMasterBCH[]) => {
"2021_invalid"?: VmbTest[] | undefined;
"2021_standard"?: VmbTest[] | undefined;
"2021_invalid"?: VmbTest[] | undefined;
"2021_nonstandard"?: VmbTest[] | undefined;
"2022_invalid"?: VmbTest[] | undefined;
"2022_standard"?: VmbTest[] | undefined;
"2022_invalid"?: VmbTest[] | undefined;
"2022_nonstandard"?: VmbTest[] | undefined;
chip_cashtokens_invalid?: VmbTest[] | undefined;
chip_cashtokens_standard?: VmbTest[] | undefined;
chip_cashtokens_invalid?: VmbTest[] | undefined;
chip_cashtokens_nonstandard?: VmbTest[] | undefined;
chip_limits_invalid?: VmbTest[] | undefined;
chip_limits_standard?: VmbTest[] | undefined;
chip_limits_invalid?: VmbTest[] | undefined;
chip_limits_nonstandard?: VmbTest[] | undefined;
chip_loops_invalid?: VmbTest[] | undefined;
chip_loops_standard?: VmbTest[] | undefined;
chip_loops_invalid?: VmbTest[] | undefined;
chip_loops_nonstandard?: VmbTest[] | undefined;
chip_minimalbool_invalid?: VmbTest[] | undefined;
chip_minimalbool_standard?: VmbTest[] | undefined;
chip_minimalbool_invalid?: VmbTest[] | undefined;
chip_minimalbool_nonstandard?: VmbTest[] | undefined;
chip_p2sh32_invalid?: VmbTest[] | undefined;
chip_p2sh32_standard?: VmbTest[] | undefined;
chip_p2sh32_invalid?: VmbTest[] | undefined;
chip_p2sh32_nonstandard?: VmbTest[] | undefined;
chip_strict_checkmultisig_invalid?: VmbTest[] | undefined;
chip_strict_checkmultisig_standard?: VmbTest[] | undefined;
chip_strict_checkmultisig_invalid?: VmbTest[] | undefined;
chip_strict_checkmultisig_nonstandard?: VmbTest[] | undefined;
chip_zce_invalid?: VmbTest[] | undefined;
chip_zce_standard?: VmbTest[] | undefined;
chip_zce_invalid?: VmbTest[] | undefined;
chip_zce_nonstandard?: VmbTest[] | undefined;

@@ -165,0 +165,0 @@ };

@@ -7,3 +7,3 @@ /**

import { authenticationTemplateToCompilerConfiguration } from '../compiler/compiler-utils.js';
import { sha256 } from '../crypto/default-crypto-instances.js';
import { sha256 } from '../crypto/crypto.js';
import { binToHex, flattenBinArray } from '../format/format.js';

@@ -10,0 +10,0 @@ import { encodeTransaction, encodeTransactionOutputs, } from '../message/message.js';

@@ -0,1 +1,40 @@

### Draft v2 Notes
Libauth is now a [pure ESM package](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c), simplifying the developer experience by allowing WASM crypto to be instantiated internally/automatically by default 🎉. This refactor also simplifies the usage of and types surrounding Libauth virtual machines and compilers, and several other APIs have been improved.
New, dedicated Telegram channels are also available for [Libauth release announcements](https://t.me/libauth) and [Libauth developer discussions](https://t.me/libauth_devs).
## Simplified Virtual Machine Types
Previously, Libauth VMs were very strictly-typed such that error messages and opcodes used chain-specific enums (e.g. `AuthenticationErrorBCH` and `OpcodesBCH`). While this configuration did ensure that VMs and VM results were strictly-typed with chain information, the configuration ultimately made library components much harder to remix without deep knowledge of TypeScript's type system. In both cases, such type information rarely catches downstream implementation bugs:
* Differing opcode enums effectively only narrow the real-time type from `number` to `0 | 1 | 2 | ... | 254 | 255`.
* Differing error enums only offer a slight benefit in making error matching slightly simpler, and they present a significant disadvantage in that they preclude the contextualization of errors – each error string must be fully defined at compile time.
In both cases, the differing types offer only very marginal benefit at the cost of exceptional added complexity (widespread proliferation of generic types throughout the codebase). This refactor migrates the opcode type to `number` and the error type to `string | undefined`, leaving the opcode and error enums primarily as a form of documentation.
## Simplified VM Usage
Transaction validation infrastructure is now a part of each VM instance, so transaction validation is as simple as `vm.verify({ transaction, sourceOutputs })` (returning either `true` or an error `string`). This behavior offers individual VMs full control of transaction parsing and validation, allowing Libauth VMs to implement proposals for significant modifications like new transaction formats or high-level transaction validation changes.
## Simplified VM Operations and Instruction Sets
Beginning with this version, Libauth will no longer maintain support for defunct VM versions. For example, `BCH_2019_05` was an upgrade which enabled Schnorr signature support in CHECKSIG and CHECKDATASIG and a clean-stack exception for SegWit recovery. The `BCH_2019_05` VM was replaced without a network split by the `BCH_2019_11` upgrade, meaning `BCH_2019_05` is no longer in use by any public network. As such, relevant code paths, flags, and other VM-specific functionality for `BCH_2019_05` has been removed to simplify currently supported Libauth VMs. (Of course, historical implementations will always remain available in previously-released versions of Libauth.)
With this change, the existing VM implementations have been significantly simplified, removing unused code and reducing type complexity. Built-in VM instruction sets are now specified in a single file, making them easier to review and copy.
## Additional Changes
Several other improvements have been made:
* **Default crypto interface instances** – because Libauth is now pure ESM, all of Libauth's WebAssembly cryptography implementations can now be automatically instantiated internally by the library. All Libauth methods that require crypto now use these automatically-instantiated implementations by default (as a default parameter), but consumers can opt-out of the behavior by providing a replacement implementation (and build tools that support dead code elimination/tree shaking of default parameters can automatically drop the unused crypto implementations.) To support this functionality, the parameter ordering of many functions have been modified to shift crypto implementations to the end (as optional parameters).
* **`Secp256k1` doesn't throw** - the `Secp256k1` interface previously threw errors, breaking from Libauth's convention of well-typed errors. All `Secp256k1` methods now return error messages as `string`s where applicable.
* **CashAssembly** – is the new name for Bitauth Templating Language (BTL), the simple language used within Libauth templates.
* **Consistent capitalization, miscellaneous corrections** – some exports have been renamed to consistently use camelCase (for functions) or PascalCase (for types/interfaces), respectively. Several exports have been renamed for discoverability and consistency with other exports.
* **Expanded state available to VMs and compilers** – VM and compiler operations can now access all raw contents of transactions and source outputs.
* **Expanded capabilities of template scenarios** – scenarios can now represent any transaction shape and generate full, serializable transactions.
* **New VM bytecode test vector generation** – Libauth includes a new `vmb_tests` test vector generation system to produce sets of cross-implementation test vectors as serialized transactions; this allows for sets of test vectors that fully test all transaction validation infrastructure without making assumptions about implementation internals.
---
# Changelog

@@ -5,2 +44,9 @@

## [2.0.0-alpha.3](https://github.com/bitauth/libauth/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2022-05-20)
### Features
* add hash160, hash256, and encodeLockingBytecode* utils ([c2a787c](https://github.com/bitauth/libauth/commit/c2a787cbdd96354edc4245601e23051ef4ee8e5e))
## [2.0.0-alpha.2](https://github.com/bitauth/libauth/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2022-05-19)

@@ -7,0 +53,0 @@

{
"name": "@bitauth/libauth",
"version": "2.0.0-alpha.2",
"version": "2.0.0-alpha.3",
"description": "ultra-lightweight library for Bitcoin Cash, Bitcoin, and Bitauth",
"type": "module",
"exports": "./build/index.js",
"main": "./build/index.js",
"types": "./build/index.d.ts",

@@ -8,0 +8,0 @@ "repository": "https://github.com/bitauth/libauth",

@@ -16,24 +16,21 @@ <p align="center">

<a href="https://www.npmjs.com/package/@bitauth/libauth">
<img
src="https://img.shields.io/npm/v/@bitauth/libauth.svg"
alt="NPM version"
/>
<img src="https://img.shields.io/npm/v/@bitauth/libauth.svg" alt="NPM version" />
</a>
<a href="https://codecov.io/gh/bitauth/libauth">
<img
src="https://img.shields.io/codecov/c/github/bitauth/libauth/master.svg"
alt="Codecov"
/>
<img src="https://img.shields.io/codecov/c/github/bitauth/libauth/master.svg" alt="Codecov" />
</a>
<a href="https://circleci.com/gh/bitauth/libauth">
<img
src="https://img.shields.io/circleci/project/github/bitauth/libauth/master.svg"
alt="CircleCI"
/>
<a href="https://github.com/bitauth/libauth/actions/workflows/ci.yaml">
<img src="https://img.shields.io/github/workflow/status/bitauth/libauth/Lint,%20Build,%20and%20Test%20Libauth?logo=github" alt="CI" />
</a>
<a href="https://twitter.com/bitauth">
<img alt="Follow Bitauth on Twitter" src="https://img.shields.io/badge/follow-@bitauth-1DA1F2?logo=twitter">
</a>
<a href="https://t.me/libauth_dev">
<img alt="Join Chat on Telegram" src="https://img.shields.io/badge/chat-Libauth%20Devs-0088CC?logo=telegram">
</a>
<a href="https://www.npmjs.com/package/@bitauth/libauth">
<img alt="npm downloads" src="https://img.shields.io/npm/dm/@bitauth/libauth">
</a>
<a href="https://github.com/bitauth/libauth">
<img
src="https://img.shields.io/github/stars/bitauth/libauth.svg?style=social&logo=github&label=Stars"
alt="GitHub stars"
/>
<img src="https://img.shields.io/github/stars/bitauth/libauth.svg?style=social&logo=github&label=Stars" alt="GitHub stars" />
</a>

@@ -40,0 +37,0 @@ </p>

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc