npm install @dogejs/core. Browsers and Node 20 or later, plain ES modules, no server.
What it does
Check an address before you use it
Addresses carry a checksum. The library tells you whether one is valid, which network it belongs to and what kind it is.
One changed character fails the checksum
Mainnet and testnet addresses are told apart
Plain functions you can call anywhere
Sign a message and verify it
Prove you control an address by signing a message. Anyone can check the signature, and a changed message fails.
Signatures are 88 base64 characters
Recover the signer from the signature
The same format wallets use
Build and sign a payment
Give the builder your coins, the recipient and a change address. It works out the fee and signs. Amounts are exact whole numbers, never floats.
Choose who pays the fee, or sweep everything
Amounts are bigint koinu
Runs on the test network first
Multisig and PSBT files
Build a 2-of-3 vault, let each cosigner sign their own copy and combine them. PSBT files and transaction files carry the same transactions to other tools.
Keep recovery phrases offline, and call wipe() when you are done with a key.
A bundler can pull in one function at a time through the subpath entries, for example import { isValidAddress } from '@dogejs/core/address'. Amounts are always bigint koinu, not floats.
What you can build
Wallets and addresses
BIP39 phrases, BIP32 and BIP44 keys, P2PKH and P2SH addresses, and WIF keys. HDNode
Signed messages
Prove you own an address. Compatible with Dogecoin Core's signmessage. signMessage
Payments
Pick coins, add change and sign, with dust and fee limits checked for you. TransactionBuilder
Fees you can trust
Let the recipient pay the fee, sweep an address, or check the fee of a file you did not build. checkTransactionFee
Multisig
m-of-n P2SH wallets, with a record of which keys have signed. inspectMultisigInput
PSBT (BIP174)
Hand a transaction to another wallet or tool, and take it back signed. signPsbt
Transaction files
A versioned JSON file that carries a payment from the machine that builds it to the one that signs it. parseTxFile
Examples
Who pays the fee
By default you pay the fee on top. With subtractFeeFrom the recipient pays it, and buildSweep sends everything to one address.
JavaScript
import { TransactionBuilder, buildSweep, formatDoge, parseDoge, testnet } from'@dogejs/core';
// coins: two made-up coins, 6 and 4 DOGE, each with its prevTxHexconst built = new TransactionBuilder({ network: testnet, requirePrevTx: true })
.addUtxo(coins[0]).addUtxo(coins[1])
.addOutput(shopAddress, parseDoge('4'))
.setChangeAddress(changeAddress)
.build();
built.mode; // 'standard'
built.tx.outputs.map((o) => formatDoge(o.value)); // ['4', '1.99774']
formatDoge(built.fee); // '0.00226'
2-of-3 multisig
Three people hold keys, any two can spend. inspectMultisigInput reports who has signed and who is missing.
JavaScript
import { multisigScript, p2shAddressFromScript, p2shScriptForRedeemScript, signInputs,
combineMultisigInput, inspectMultisigInput, verifyInput, testnet } from'@dogejs/core';
const redeem = multisigScript(2, [pubA, pubB, pubC]);
const address = p2shAddressFromScript(redeem, testnet);
const prevScript = p2shScriptForRedeemScript(redeem);
// built: an unsigned transaction that spends a coin held by addressconst first = signInputs(built.tx, built.prevouts, [wifA]); // OP_0 <sigA> OP_0 <redeem>const other = signInputs(built.tx, built.prevouts, [wifC]); // same unsigned txconst both = combineMultisigInput(first, 0, [other.inputs[0].scriptSig], redeem, prevScript);
// Signed so far in this demo: nobody
inspectMultisigInput(both, 0, redeem, prevScript);
// signed keys [], missing [0,1,2], complete false
A transaction file
Build on one machine, sign on another. The file is read strictly and carries a checksum. Change one digit and the file is refused.
JavaScript
import { createTxFile, serializeTxFile, parseTxFile, addTxFileSignatures, signInputs, testnet } from'@dogejs/core/txfile';
// signInputs comes from '@dogejs/core'// online machine: write the fileconst file = createTxFile({ network: testnet, tx: built.tx, prevouts: built.prevouts, changeIndex: built.changeIndex, requirePrevTx: true });
const text = serializeTxFile(file);
// offline machine: read it strictly, sign, write it backconst f = parseTxFile(text, { network: testnet, requirePrevTx: true });
const signed = addTxFileSignatures(f, signInputs(f.tx, f.inputs, [wif]));
signed.state; // 'signed'
parseTxFile(editedText); // throws DogeError FILE_CHECKSUM after any edit
Share a transaction as a PSBT
A PSBT (BIP174) is the file other wallets and hardware-wallet tools pass around. @dogejs/core/psbt reads and writes version 0. Dogecoin has no SegWit, so SegWit fields are refused. The signer only signs with the full previous transaction, and takes the amounts from it alone.
JavaScript
import { TransactionBuilder, parseDoge, testnet } from '@dogejs/core';
import {
psbtFromBuiltTransaction, psbtToBase64, decodePsbt, inspectPsbt,
signPsbt, finalizePsbt, extractPsbtTransaction,
} from '@dogejs/core/psbt';
// coin: a made-up 10 DOGE coin with its prevTxHex
const built = new TransactionBuilder({ network: testnet, requirePrevTx: true })
.addUtxo(coin)
.addOutput(shop, parseDoge('7.5'))
.setChangeAddress(changeAddress)
.build();
const text = psbtToBase64(psbtFromBuiltTransaction(built, { network: testnet }));
// text starts "cHNidP8B...": give it to a wallet, a cosigner or a hardware-wallet tool
const psbt = decodePsbt(text);
inspectPsbt(psbt, { network: testnet }).fee; // 226000n koinu: show this before anyone signs
const done = finalizePsbt(signPsbt(psbt, [wif]).psbt);
done.complete; // true
const tx = extractPsbtTransaction(done.psbt); // verified, ready to broadcast
For several signers, call signPsbt on each copy and join them with combinePsbts before finalizePsbt. Files convert both ways with psbtToTxFile and txFileToPsbt. The decoder and multisig page open PSBTs, and dogejs psbt works with them on the command line.
How it is tested
The package has 1,633 tests, and the Dogecoin-specific rules come from other people's code, not only ours. The test files carry vectors taken from Dogecoin Core (signature hashes, valid and invalid transactions, scripts, Base58, BIP32), the BIP32, BIP39 and BIP174 reference vectors, and the Dogecoin Foundation's C library, libdogecoin.
For libdogecoin we built it from source (commit bf3f9df), ran its own tests, then asked it the same questions as DogeJS and compared the answers byte for byte. It is a test oracle only, not a dependency.
Compared with libdogecoin
Cases
Result
P2PKH addresses, mainnet, testnet and regtest
48
identical
WIF encode and decode
72
identical
BIP32 nodes (keys, extended keys, addresses)
108
identical
BIP39 phrases, seeds and BIP44 addresses
7 phrases
identical
Transaction signatures, P2PKH, all six hash types
8
byte-identical
Message signatures, 4 keys and 11 messages
44
identical for 1 to 252 bytes, and each verifies the other's
PSBT workflows (single key, 2-of-3, out of order)
4
identical; libdogecoin reads, finalizes and extracts ours
The comparison found three bugs in libdogecoin and none in DogeJS: its raw-transaction multisig signer writes the redeem script without the right push, so 2-of-3 inputs never verify; its message hash differs from Dogecoin Core for empty and 253-byte or longer messages; and its PSBT signer adds signatures to inputs it cannot sign. PSBT files are checked against libdogecoin and the BIP174 test vectors.
Details and every vector: test/vectors/libdogecoin/README.md and docs/PSBT.md in the package.
Reference
Modules and key functions
Every module is also an import path, for example @dogejs/core/hd. The main entry exports all of them.
Every function throws a DogeError with a code, for example INVALID_CHECKSUM, WRONG_NETWORK, INSUFFICIENT_FUNDS, FEE_TOO_HIGH, FEE_TOO_LOW, DUST_OUTPUT, UTXO_MISMATCH or FILE_CHECKSUM.
Import paths and bundle sizes
Measured with esbuild 0.24, minified, with everything a consumer needs included. Import from the subpath entries when you bundle.
You import
Minified
Gzipped
parseDoge from @dogejs/core/amount
910 B
528 B
networkFromGenesisHash from @dogejs/core/networks
1,375 B
778 B
isValidAddress from @dogejs/core/address
9,342 B
4,225 B
TransactionBuilder and signInputs
80,232 B
28,786 B
parseTxFile from @dogejs/core/txfile
86,969 B
31,039 B
decodePsbt and signPsbt from @dogejs/core/psbt
72,640 B
26,856 B
isValidAddress from the main entry
78,086 B
32,179 B
All of dist/index.mjs (one file, for a CDN)
197,721 B
68,103 B
Network constants
Name
mainnet
testnet
regtest
P2PKH version byte
0x1e (D...)
0x71 (n...)
0x6f
P2SH version byte
0x16
0xc4
0xc4
WIF version byte
0x9e
0xf1
0xef
Extended public key
dgub
tpub
tpub
BIP44 coin type
3
1
1
Genesis block hash
1a91e3da...
bb0a7826...
3d2160a3...
Fee and dust constants
From Dogecoin Core 1.14.99. Node operators can change them.
Constant
Value
Meaning
RECOMMENDED_FEE_RATE
0.01 DOGE/kB
Default fee rate of the builder.
MIN_RELAY_FEE_RATE
0.001 DOGE/kB
Below this, nodes do not relay.
SOFT_DUST_LIMIT
0.01 DOGE
Relay adds a fee for each output below it.
HARD_DUST_LIMIT
0.001 DOGE
Outputs below it are non-standard.
DEFAULT_MAX_TX_FEE
100 DOGE
Absolute fee limit (maxFee).
DEFAULT_MAX_FEE_MULTIPLE
10
Relative limit (maxFeeMultiple): ten times the expected fee, plus any leftover allowance.
Run examples
Each example below was run now against the built package, on testnet, and the output is what it printed. They share one helper that makes a funding transaction the way a backend would hand you one:
JavaScript (common.mjs)
// Shared helper for the examples: makes a "funding" transaction (a coin that pays `address`), the way a chain backend would hand you one.
import { TransactionBuilder, addressToScript, signInputs, encodeTransactionHex, getTxid, parseDoge, testnet } from '@dogejs/core';
export function fund(address, fromKeyWif, fromAddress, doge = '10') {
const b = new TransactionBuilder({ network: testnet, requirePrevTx: false })
.addUtxo({ txid: 'bb'.repeat(32), vout: 0, value: parseDoge('50'), script: addressToScript(fromAddress, testnet) })
.addOutput(address, parseDoge(doge))
.setChangeAddress(fromAddress)
.build();
const signed = signInputs(b.tx, b.prevouts, [fromKeyWif]);
return { txid: getTxid(signed), hex: encodeTransactionHex(signed), vout: 0, value: parseDoge(doge) };
}
Run: Keys and an HD wallet
JavaScript
import { HDNode, generateMnemonic, validateMnemonic, bip44Path, testnet, mainnet } from '@dogejs/core';
// A fixed 32-byte seed keeps this output the same on every run (never use a fixed seed for real money).
const seed = new Uint8Array(32).fill(7);
const root = HDNode.fromSeed(seed, mainnet);
for (let i = 0; i < 3; i++) {
const path = bip44Path({ account: 0, change: 0, index: i }); // m/44'/3'/0'/0/i on mainnet
console.log(path, root.derive(path).toAddress());
}
// The account-level public key can make every address without ever holding a private key.
const account = root.derive("m/44'/3'/0'");
const watchOnly = HDNode.fromExtendedKey(account.toExtendedPublicKey());
console.log('watch-only index 0 matches:', watchOnly.derive('0/0').toAddress() === root.derive("m/44'/3'/0'/0/0").toAddress());
console.log('can sign:', watchOnly.isPrivate);
// A recovery phrase: 24 words by default. Only its size and validity are shown here.
const phrase = generateMnemonic();
console.log(phrase.split(' ').length, 'words, valid:', validateMnemonic(phrase));
console.log('testnet path:', bip44Path({ network: testnet }));
root.wipe();
Decodes and validates a Dogecoin address. Mirrors Core's CBitcoinAddress::IsValid (src/base58.cpp:252-258): a 20-byte payload with the network's PUBKEY_ADDRESS or SCRIPT_ADDRESS version.
DecodedAddress
interface
{ type, hash, network, networks }
Result of decodeAddress: the address kind, its 20-byte hash and the network(s) whose version byte it carries.
Formats koinu as a decimal DOGE string. Trailing zeros are trimmed down to `minDecimals`. Negative values are formatted with a leading `-` (useful for balance deltas); parseDoge does not accept them back.
FormatOptions
interface
{ minDecimals? }
Options for formatDoge.
isMoneyRange
function
isMoneyRange(koinu: bigint): boolean;
True if `value` is between 0 and MAX_MONEY, in koinu.
KOINU_PER_DOGE
const
KOINU_PER_DOGE = 100000000n
Koinu per DOGE. Dogecoin Core src/amount.h:18 `static const CAmount COIN = 100000000;` Amounts are always `bigint` koinu; no floating point is used anywhere.
MAX_MONEY
const
MAX_MONEY: bigint
Largest amount of money in koinu: 10 billion DOGE (Core's MAX_MONEY). A sanity limit, not the supply.
parseDoge
function
parseDoge(input: string): bigint;
Parses a decimal DOGE string into koinu.
parseKoinu
function
parseKoinu(input: string): bigint;
Parses a koinu integer string (digits only, non-negative).
One-call sweep: spends every UTXO in `utxos` to `to`, with the fee taken from that output (TransactionBuilder.sweepTo). `data` adds one OP_RETURN output.
How the builder picks inputs: `largest-first` (default), `in-order` (as given) or `all` (spend every UTXO added).
DEFAULT_MAX_FEE_MULTIPLE
const
DEFAULT_MAX_FEE_MULTIPLE = 10
Default of BuilderOptions.maxFeeMultiple: the fee may be at most 10 times the fee the builder expects (plus the leftover allowance). DogeJS policy, not a Dogecoin Core constant; Core only has the absolute -maxtxfee (src/validation.h:62).
FeeCheckFailure
interface
{ code, guard, message }
One failed guard of checkTransactionFee: the error code it stands for, which guard failed, and a message.
Builds an unsigned transaction: add UTXOs and outputs, then call TransactionBuilder.build. Selects coins, computes the fee, adds change and enforces the fee, dust and standardness guards; throws DogeError (INSUFFICIENT_FUNDS, FEE_TOO_HIGH, DUST_OUTPUT, UTXO_UNVERIFIED and others) instead of building a bad transaction. Amounts are koinu.
An unspent output to spend with TransactionBuilder: outpoint, value in koinu, script and, for P2SH, the redeem script.
verifyUtxo
function
verifyUtxo(utxo: Utxo): void;
Authenticates a UTXO's value and script against its full previous transaction (`utxo.prevTxHex`). Throws DogeError: - UTXO_UNVERIFIED if `prevTxHex` is missing; - UTXO_MISMATCH if `prevTxHex` is not a valid legacy transaction, if its txid (double SHA-256 of exactly these bytes, displayed byte-reversed) is not `utxo.txid`, if it has no output `utxo.vout`, or if that output's value or scriptPubKey differ from `utxo.value` / `utxo.script`; - INVALID_ARGUMENT / INVALID_AMOUNT for a malformed UTXO.
bytes17 exports
Name
Kind
Signature
What it does
base58checkDecode
function
base58checkDecode(input: string): Uint8Array;
Base58Check decoding with distinct error codes. Returns the payload (version byte(s) included) without the 4-byte checksum.
base58checkEncode
function
base58checkEncode(payload: Uint8Array): string;
Base58Check encoding (version and payload already concatenated).
Strict hex decoding: even length, hex digits only (either case), no prefix or whitespace.
hexToHash
function
hexToHash(hex: string): Uint8Array;
Internal (wire) order bytes of a displayed 64-hex-character hash (the reverse of hashToHex).
MAX_COMPACT_SIZE
const
MAX_COMPACT_SIZE = 33554432
Core's MAX_SIZE for CompactSize values, src/serialize.h:26 `static const unsigned int MAX_SIZE = 0x02000000;`
ripemd160
const
ripemd160: CHash
RIPEMD-160 - a legacy hash function from 1990s. * https://homes.esat.kuleuven.be/~bosselae/ripemd160.html * https://homes.esat.kuleuven.be/~bosselae/ripemd160/pdf/AB-9601/AB-9601.pdf
Extra fee in koinu that Core charges for dust outputs: `limit` for each one.
ESTIMATED_SIGNATURE_SIZE
const
ESTIMATED_SIGNATURE_SIZE = 72
Signature size assumed by estimates: 72 bytes including the hash-type byte, as Core's DummySignatureCreator (src/script/sign.cpp:412-426). A low-S DER signature is at most 71 bytes plus the hash type, so this is an upper bound.
Serialized size of a legacy transaction with the given inputs and outputs. Exact for the given scriptSig sizes; for P2PKH/multisig descriptors it assumes 72-byte signatures, so real signed transactions are the same size or a few bytes smaller (never larger). Typical values: 1-in/2-out P2PKH = 226 bytes, one P2PKH input = 148 bytes, one 2-of-3 P2SH input = 297 bytes.
Options for bip44Path: account, change chain and address index, all non-negative integers below 2^31.
bip44Path
function
bip44Path(options?: Bip44Options): string;
BIP44 path `m/44'/coin'/account'/change/index`; on mainnet `m/44'/3'/0'/0/0` by default.
coreHdPath
function
coreHdPath(index: number): string;
The fixed path Dogecoin Core 1.14's own HD wallet uses for its n-th key: `m/0'/3'/n'` (src/wallet/wallet.cpp:132-170, CWallet::DeriveNewChildKey). Only useful together with Core's HD master key (`hdmasterkeyid`).
englishWordlist
const
englishWordlist: readonly string[]
The BIP39 English wordlist (default everywhere). Other lists: import from `@scure/bip39/wordlists/*`.
Generates a BIP39 mnemonic (12 words for 128 bits ... 24 words for 256 bits) from `crypto.getRandomValues` via `@scure/bip39`. Default 256 bits (24 words).
HARDENED_OFFSET
const
HARDENED_OFFSET = 2147483648
BIP32 hardened index offset (Core: BIP32_HARDENED_KEY_LIMIT, src/wallet/wallet.cpp:50).
BIP39 seed (64 bytes, PBKDF2-HMAC-SHA512, 2048 rounds). The mnemonic is validated against `wordlist` first: unlike raw BIP39, an invalid mnemonic is rejected rather than silently producing a seed.
Recovers the signer of a base64 message signature. Returns the public key and the P2PKH address it corresponds to on `network`. Throws DogeError on malformed input.
Low-level: 65-byte compact recoverable signature of a 32-byte hash, as Core's CKey::SignCompact. RFC 6979 deterministic nonces and low-S, both as libsecp256k1 in Core; the signing itself is done by `@noble/curves`.
Parameters that tell the networks apart: name, address and WIF version bytes, BIP32 versions, message magic and BIP44 coin type. Use mainnet, testnet or regtest.
The built-in network whose genesis block has this hash, or `undefined` if none does. `hash` is 64 hex characters in displayed order (either case; no `0x` prefix). Throws INVALID_ARGUMENT for anything else. Use it to check that a node or indexer serves the chain you expect before trusting any other answer from it.
NetworkName
type
NetworkName = 'mainnet' | 'testnet' | 'regtest';
Name of a built-in network: `mainnet`, `testnet` or `regtest`.
NETWORKS
const
NETWORKS: readonly Network[]
All built-in networks, in detection priority order.
regtest
const
regtest: Network
Dogecoin regression-test network parameters (address versions 0x6f and 0xc4, WIF 0xef, BIP44 coin type 1). Frozen.
testnet
const
testnet: Network
Dogecoin test network parameters (address versions 0x71 and 0xc4, WIF 0xf1, BIP44 coin type 1). Frozen.
TESTNET_COIN_TYPE
const
TESTNET_COIN_TYPE = 1
BIP44 coin type 1, the SLIP-0044 type for "Testnet (all coins)"; used on testnet and regtest.
Low-level Updater: adds raw records (for example proprietary ones). Every record is validated as on reading; a key already present with a different value is PSBT_MISMATCH.
Combiner: merges PSBTs of the same unsigned transaction (PSBT_MISMATCH otherwise) into one with every record of each. The result is in canonical order, so it does not depend on the order of the PSBTs given.
createPsbt
function
createPsbt(tx: Transaction): Psbt;
Creator: a PSBT for an unsigned transaction, with empty input and output maps. The transaction must be strict legacy, with every scriptSig empty, and smaller than a standard transaction.
Extractor: the network transaction, with each input's final scriptSig. Throws PSBT_INCOMPLETE if an input is not final. Unless `verify: false`, every input must carry its previous transaction (UTXO_UNVERIFIED) and the whole transaction must verify (INVALID_SIGNATURE).
finalizePsbt
function
finalizePsbt(psbt: Psbt): PsbtFinalizeResult;
Builds the final scriptSigs of every input that has enough valid signatures.
Limits applied to every PSBT read. Derivations: - the unsigned transaction must be smaller than a standard transaction (100,000 bytes, MAX_STANDARD_TX_WEIGHT / 4, Dogecoin Core src/policy/policy.h:34); - one previous transaction is at most 1,000,000 bytes (MAX_TX_SIZE, the consensus block size, src/consensus/consensus.h:17); - `maxBytes` bounds the whole PSBT (10 MB, e.g. 100 inputs with 100 kB previous transactions); base64 and hex text are bounded to match before decoding.
PSBT_MAGIC
const
PSBT_MAGIC: Uint8Array
The 5 magic bytes every PSBT starts with: "psbt" and 0xff.
One input of a PSBT: previous transaction, redeem script, partial signatures, sighash type, final scriptSig and derivation paths, plus every record in file order.
What inspectPsbt reports about one input: outpoint, the output it spends (if known, and whether that is proven), signature count and whether it is final.
A PSBT as a DogeJS transaction file. Each input needs its value and script: from its previous transaction, or from a "dogejs" prevout record (UTXO_UNVERIFIED otherwise). Partial signatures and final scriptSigs become the file's signatures, which are all verified. BIP32 derivations, extended keys, sighash type fields, output redeem scripts, unknown, foreign proprietary and SegWit records have no place in the file: they are listed in `dropped`.
PsbtToTxFileOptions
interface
{ network?, requirePrevTx?, changeIndex? }
Options for psbtToTxFile.
PsbtToTxFileResult
interface
{ file, dropped }
Result of psbtToTxFile: the transaction file and a plain-language list of what a transaction file cannot hold.
PsbtXpub
interface
{ xpub, fingerprint, path }
A global extended public key record of a PSBT: the 78-byte xpub, the master fingerprint and the derivation path.
Signer: signs every input it can with `keys` (raw 32-byte keys or WIF) and adds the signatures as partial signatures. Signatures are deterministic (RFC 6979, low S), byte-identical to signInputs for the same transaction and key.
Classifies a scriptPubKey exactly as Core's Solver does. Like Core, pushes are matched by length only (a P2PKH template written with OP_PUSHDATA1 still matches; P2PK/multisig keys are 33..65-byte pushes that are not checked to be valid points). Witness programs are reported, but they are not standard on Dogecoin, where SegWit is not active (see isStandardScriptPubKey).
Serializes a script. Each element is either an opcode number (a non-push opcode, or OP_0), a Uint8Array (pushed minimally with encodePush), or a ScriptChunk (serialized with exactly its opcode, so that `compileScript(decompileScript(s))` reproduces `s` byte for byte).
Address of a canonical P2PKH or P2SH scriptPubKey. Throws INVALID_SCRIPT for anything else, including P2PK and multisig (Core's ExtractDestination maps P2PK to the key's P2PKH address; DogeJS does not, because paying that address would create a different script) and non-canonical encodings.
Lists which public keys have validly signed P2SH multisig input `inputIndex`, and which are still missing. `prevScript` must be the P2SH scriptPubKey of `redeemScript` (INVALID_SCRIPT otherwise). An empty scriptSig means nothing is signed yet; a scriptSig that is not a multisig scriptSig for this redeem script throws INVALID_SCRIPT. Each signature is checked against every key with verifyInputSignature; `complete` comes from verifyInput, so it also requires Core's in-order matching and the OP_0 dummy.
Signs P2PKH input `inputIndex`, which spends an output with scriptPubKey `prevScript`. Throws if the key does not match the script's public-key hash. Returns a new transaction; the input's scriptSig becomes `<sig> <pubkey>`.
Adds one signature to P2SH multisig input `inputIndex`. `prevScript` must be the P2SH scriptPubKey of `redeemScript`. Existing signatures in the input's scriptSig are kept; the result is always in Core's format (key order, OP_0 dummy, OP_0 placeholders while incomplete), so it can be passed to another signer, to combineMultisigInput, or to Core's signrawtransaction.
Checks the signatures of input `inputIndex` against `prevScript`, the scriptPubKey of the output it spends. Supports P2PKH, P2PK, bare multisig and P2SH wrapping any of those. Never throws for bad signatures or scripts; see the module notes for what this does not check.
Parses a legacy transaction from bytes or hex. Strict: canonical CompactSize only (as Core), no trailing bytes, no truncation. The BIP144 witness encoding is rejected with INVALID_TRANSACTION (SegWit is not active on Dogecoin).
encodeTransaction
function
encodeTransaction(tx: Transaction): Uint8Array;
Serializes a transaction in the legacy (non-witness) format.
encodeTransactionHex
function
encodeTransactionHex(tx: Transaction): string;
Lowercase hex of encodeTransaction.
getTransactionSize
function
getTransactionSize(tx: Transaction): number;
Serialized size in bytes. For legacy transactions this is also Core's virtual size used for fees.
getTxid
function
getTxid(tx: Transaction | Uint8Array): string;
Transaction id: double SHA-256 of the serialization, displayed byte-reversed (Core uint256::GetHex).
isValidTransaction
function
isValidTransaction(tx: Transaction): boolean;
True if Core's CheckTransaction would accept `tx`. Never throws.
MAX_STANDARD_TX_VERSION
const
MAX_STANDARD_TX_VERSION = 2
Highest transaction version Core relays as standard (2).
MAX_TX_SIZE
const
MAX_TX_SIZE = 1000000
Largest serialized transaction, in bytes (1,000,000), a consensus limit.
normalizeTxid
function
normalizeTxid(txid: string): string;
Validates and normalizes a displayed txid (64 hex chars) to lowercase.
SEQUENCE_FINAL
const
SEQUENCE_FINAL = 4294967295
Input sequence number 0xffffffff: the input is final and ignores locktime.
Transaction
interface
{ version, inputs, outputs, locktime }
A decoded legacy Dogecoin transaction (no SegWit). Amounts are koinu (bigint); txids are displayed hex.
TX_VERSION_DEFAULT
const
TX_VERSION_DEFAULT = 1
Default transaction version (1).
TxInput
interface
{ txid, vout, scriptSig, sequence }
A transaction input: the outpoint (previous txid and output index), the scriptSig and the sequence number.
TxOutput
interface
{ value, script }
A transaction output: value in koinu and scriptPubKey.
Adds the signatures of a further-signed copy of the same transaction to a transaction file.
canonicalJson
function
canonicalJson(value: unknown): string;
Canonical JSON of a JSON value (see the module notes). Throws FILE_SCHEMA for anything that is not a JSON value these files allow (undefined, bigint, non-integer or unsafe numbers, functions, class instances, unpaired surrogates) and FILE_TOO_LARGE past 64 levels of nesting.
Creates a descriptor for an m-of-n P2SH multisig. Keys are used in the order given (sort them yourself, e.g. BIP67, if your group agreed to). Throws as multisigScript: INVALID_ARGUMENT, INVALID_PUBLIC_KEY, NON_STANDARD.
createTxFile
function
createTxFile(params: CreateTxFileParams): TxFile;
Creates a validated transaction file. Every check parseTxFile makes is applied, so a file you create always reads back. Throws the same errors.
Input of createTxFile: the network, a transaction (unsigned or partly signed), the output each input spends, and optional change index, fee rate, time and note.
FileSource
interface
{ format, version, checksummed }
Where a parsed file came from.
FORBIDDEN_JSON_KEYS
const
FORBIDDEN_JSON_KEYS: readonly string[]
Keys rejected anywhere in a file (prototype-pollution vectors in naive consumers).
jsonChecksum
function
jsonChecksum(body: unknown): string;
The checksum string (`sha256:` plus hex) of a file body's canonical JSON.
Text of a version 2 descriptor (two-space indented JSON and a final line break).
serializeTxFile
function
serializeTxFile(file: TxFile): string;
The text of a version 2 file: JSON with two-space indentation and a final line break. Always writes version 2, also for a file read from version 1 (this is the migration). Round-trip: `parseTxFile(serializeTxFile(f))` gives the same file.
TX_FILE_FORMAT
const
TX_FILE_FORMAT = "dogejs-tx"
The `format` string of a transaction file (`dogejs-tx`).
Limits enforced on every file read (and on files created). Derivations: - a standard transaction is under 100,000 bytes (MAX_STANDARD_TX_WEIGHT / 4, src/policy/policy.h:34) and an input is at least 41 bytes, so it has fewer than 2,440 inputs: `maxInputs` 2,500; an output is at least 9 bytes: `maxOutputs` 10,000; - one previous transaction is at most 1,000,000 bytes (MAX_BLOCK_BASE_SIZE, src/consensus/consensus.h:17), 2,000,000 hex characters: `maxStringLength`; - `maxTextLength` 16,000,000 characters bounds the whole file; - the transaction itself must be smaller than a standard transaction (100,000 bytes): a node would not relay a larger one, and this bounds the signature checks.
Validates a parsed descriptor: version 2, the command-line tool's "dogejs-multisig" v1, or the browser tools' "dogejs-multisig-descriptor" v1. Everything is re-derived from m, the keys and the network; any difference is FILE_MISMATCH. Other errors: FILE_FORMAT, FILE_VERSION, FILE_SCHEMA, FILE_CHECKSUM, WRONG_NETWORK.
Validates an already-parsed JSON value as a transaction file: version 2, or one of the legacy formats (see the module notes). Prefer parseTxFile, which also applies the size, depth and key rules to the text.
git clone https://github.com/DogeJS-Dev/core
cd core
npm install
npm run build
npm test
FAQ
Does it work in the browser?
Yes. It is plain TypeScript with no Node-only code; the examples above also run in Node 20+.
Why bigint?
Money is a bigint count of koinu (1 DOGE = 100,000,000 koinu), never a float, so no rounding error can change an amount.
Does it talk to the network?
No. It builds, signs and checks. Fetching coins and broadcasting is the job of backends.
Are the keys safe to paste into a web page?
Keep real keys on a machine you control. The browser tools run locally and send nothing, but a key in clipboard history or a screenshot is still exposed.