Skip to content

Commit b9e6e0e

Browse files
committed
Merge branch 'v2'
2 parents 5cfd5ac + c20bd0b commit b9e6e0e

317 files changed

Lines changed: 67486 additions & 30800 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.ava.bench.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export default {
2-
files: ['build/main/**/*.bench.js'],
2+
files: ['build/**/*.bench.js'],
3+
workerThreads: false,
34
verbose: true,
45
};

.circleci/config.yml

Lines changed: 0 additions & 88 deletions
This file was deleted.

.cspell.json

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
11
{
2-
"version": "0.1",
2+
"version": "0.2",
33
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json",
44
"language": "en",
55
"words": [
6+
"ACTIVEBYTECODE",
7+
"Amagi",
68
"ANYONECANPAY",
79
"asmcrypto",
810
"auditability",
911
"auditable",
12+
"BCHCHIPs",
13+
"bchn",
1014
"bchreg",
1115
"bchtest",
1216
"bcoin",
1317
"bcrypto",
1418
"bech",
19+
"benchmarkjs",
1520
"bigint",
1621
"bindgen",
1722
"bitauth",
1823
"bitcoincash",
1924
"bitcore",
2025
"bitfield",
2126
"bitflags",
27+
"bitjson",
2228
"BOOLAND",
2329
"BOOLOR",
2430
"bytecode",
2531
"camelcase",
2632
"cashaddr",
33+
"CASHTOKENS",
2734
"CHECKDATASIG",
2835
"CHECKDATASIGVERIFY",
2936
"CHECKLOCKTIMEVERIFY",
@@ -41,21 +48,31 @@
4148
"combinators",
4249
"convertbits",
4350
"cyclomatic",
51+
"Datacarrier",
4452
"deno",
4553
"deserialization",
4654
"deserialize",
4755
"devtools",
56+
"discoverability",
57+
"Dreyzehner",
4858
"DYNAMICTOP",
4959
"ecdsa",
5060
"elliptic's",
5161
"emscripten",
5262
"emscripten's",
63+
"endianness",
5364
"EQUALVERIFY",
5465
"esnext",
66+
"FORKID",
5567
"FROMALTSTACK",
5668
"GREATERTHAN",
5769
"GREATERTHANOREQUAL",
70+
"HMAC",
5871
"IFDUP",
72+
"INPUTBYTECODE",
73+
"INPUTINDEX",
74+
"INPUTSEQUENCENUMBER",
75+
"Ints",
5976
"INVALIDOPCODE",
6077
"LESSTHAN",
6178
"LESSTHANOREQUAL",
@@ -70,17 +87,27 @@
7087
"malleated",
7188
"malleation",
7289
"malloc",
90+
"Merkle",
7391
"minification",
7492
"MINIMALIF",
7593
"monospace",
7694
"multisig",
95+
"NONFUNGIBLE",
7796
"nops",
7897
"NOTIF",
98+
"nullary",
7999
"NULLDUMMY",
80100
"NULLFAIL",
81101
"NUMEQUAL",
82102
"NUMEQUALVERIFY",
83103
"NUMNOTEQUAL",
104+
"OUTPOINTINDEX",
105+
"OUTPOINTTXHASH",
106+
"OUTPUTBYTECODE",
107+
"OUTPUTTOKENAMOUNT",
108+
"OUTPUTTOKENCATEGORY",
109+
"OUTPUTTOKENCOMMITMENT",
110+
"OUTPUTVALUE",
84111
"parsimmon",
85112
"performant",
86113
"plusplus",
@@ -98,16 +125,20 @@
98125
"reversebytes",
99126
"ripemd",
100127
"RSHIFT",
128+
"rustup",
101129
"satoshi",
102130
"satoshis",
131+
"Sats",
103132
"schnorr",
104133
"seckey",
105134
"secp",
106135
"secp256k1",
136+
"sigchecks",
107137
"sighash",
108138
"skippable",
109139
"SMALLINTEGER",
110140
"STACKTOP",
141+
"standardness",
111142
"statelessly",
112143
"STATICTOP",
113144
"submodule",
@@ -118,12 +149,23 @@
118149
"tpub",
119150
"tsdoc",
120151
"txid",
152+
"TXINPUTCOUNT",
153+
"TXLOCKTIME",
154+
"TXOUTPUTCOUNT",
155+
"TXVERSION",
121156
"typeof",
122157
"Uint",
123158
"uncompress",
124159
"unintuitive",
160+
"unspendable",
125161
"untrusted",
126162
"utxo",
163+
"UTXOBYTECODE",
164+
"utxos",
165+
"UTXOTOKENAMOUNT",
166+
"UTXOTOKENCATEGORY",
167+
"UTXOTOKENCOMMITMENT",
168+
"UTXOVALUE",
127169
"VERIF",
128170
"VERNOTIF",
129171
"wasm",
@@ -132,14 +174,28 @@
132174
"xprivkey",
133175
"xprv",
134176
"xpub",
135-
"xpubkey"
177+
"xpubkey",
178+
"𒂼𒄄"
136179
],
137180
"flagWords": [],
138181
"ignorePaths": [
182+
".cspell.json",
139183
"package.json",
140184
"yarn.lock",
141185
"tsconfig.json",
142186
"node_modules/**",
143-
"src/**/*.base64.ts"
187+
"src/**/*.base64.ts",
188+
"src/**/script_tests.json"
189+
],
190+
"patterns": [
191+
{
192+
"name": "cash-address-format",
193+
"pattern": "/:[qpzry9x8gf2tvdw0s3jn54khce6mua7l]+/g"
194+
}
195+
],
196+
"ignoreRegExpList": [
197+
"Base64",
198+
"HexValues",
199+
"cash-address-format"
144200
]
145201
}

.eslintrc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
},
2424
{ "selector": "typeLike", "format": ["PascalCase"] },
2525
{ "selector": "enumMember", "format": ["camelCase", "UPPER_CASE"] } // Allow UPPER_CASE for opcodes
26-
]
26+
],
27+
"import/no-internal-modules": ["error"],
28+
"import/extensions": ["error", "always"]
2729
},
2830
"overrides": [
2931
/*
@@ -44,7 +46,12 @@
4446
}
4547
]
4648
}
47-
]
49+
],
50+
"functional/no-expression-statement": "off",
51+
"@typescript-eslint/naming-convention": "off",
52+
"@typescript-eslint/no-magic-numbers": "off",
53+
"functional/immutable-data": "off",
54+
"functional/no-return-void": "off"
4855
}
4956
}
5057
]

.github/CONTRIBUTING.md

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Below you'll find the conventions we're trying to follow. Of course, please feel
66

77
## Design Goals
88

9-
This library should provide the primitives needed to hack on Bitcoin and Bitcoin-related ideas.
9+
This library should provide the primitives needed to hack on bitcoin and bitcoin-related ideas.
1010

1111
1. **flexible** - Consumers should be able to import only the functionality they need
1212
2. **simple** - Functions should be simple and return one type
@@ -19,36 +19,15 @@ This library should provide the primitives needed to hack on Bitcoin and Bitcoin
1919
- **trust the caller** - Runtime type-checking is a code smell. If the function accepts a string, assume it's been given a string. TypeScript definitions should expose improperly called functions to the developer at compile time, don't re-implement it at runtime. (Where TypeScript's lack of dependent types prevents us from checking the validity of an input at compile time, resist the urge to check it at runtime. Trust that the caller can test their code themselves.)
2020
- **simple > ergonomic** - Clever, javascript-y interfaces are fun until they're limiting. We export simple primitives; other projects can wrap this library to provide friendlier interfaces.
2121
- **clarity > performance** - Performance is a secondary goal. If our consumers need to squeeze out performance from a single machine, they should switch to something lower-level. The best way to speed up a consumer of this library is to parallelize it across more hardware.
22-
- **don't overvalue historical names** - Many Bitcoin implementations make imprecise (and even misleading) naming choices for historical reasons. We make little effort to match the type/function names of other Bitcoin implementations; names should be chosen to improve clarity.
22+
- **don't overvalue historical names** - Many bitcoin implementations make imprecise (and even misleading) naming choices for historical reasons. We make little effort to match the type/function names of other bitcoin implementations; names should be chosen to improve clarity.
2323
- **don't add package dependencies** - This library should be as simple and stable as possible. Generally, if something is hard enough to warrant bringing in a dependency, it's something this library should provide. (Can you compile and expose a WASM version?)
2424

2525
## Some Practical Details
2626

2727
- **accept `readonly`, return mutable** - We should always return mutable types to allow consumers the option of mutating results without running afoul of type-checking. For the same reason, when we accept a value, we should always accept it as `readonly` for maximum flexibility.
2828
- **use `eslint-disable-next-line` or `eslint-disable-line`** - It's ok to disable eslint; in some cases, rules should be disabled every time they're hit (e.g. `no-bitwise`). By using single-line disables, we clearly mark intentional deviations from our conventions.
2929
- **avoid Hungarian notation & name prefixing** – Including the type of a variable in its name is a code smell: a name should clearly describe only one concept, and types are the business of the type system. Likewise, using prefixes to distinguish between an interface and an instance typically indicates the concepts should be simplified. E.g. `IChecker` and `Checker` – this is likely made unnecessarily complex to accommodate an object-oriented style. Consider replacing with a single function (or if instantiation is required, an object containing only stateless functions).
30-
- **don't throw things** – instead, return a result which can be either successful or an error. This strategy encourages a more functional approach to problems, and pragmatically, [TypeScript does not yet offer a `throws` clause or otherwise](https://github.com/microsoft/TypeScript/issues/13219), so only this strategy allows errors to be well-typed. A good pattern is `() => string | ResultType`, where ResultType is the desired output, and error messages are returned as a string. Consumers can easily use `typeof result === 'string'` to narrow the resulting type. When errors are more complex or `ResultType` is also a string, use an object with a `success` property, e.g. `() => { success: true, bytecode: Uint8Array } | { success: false, errors: ErrorType[] }`.
30+
- **don't throw things** – instead, return a result that can be either a success or error type. This strategy encourages a more functional approach to problems, and pragmatically, [TypeScript does not yet offer a `throws` clause or otherwise](https://github.com/microsoft/TypeScript/issues/13219), so only this strategy allows errors to be well-typed. A good pattern is `() => string | ResultType`, where ResultType is the desired output, and error messages are returned as a string. Consumers can easily use `typeof result === 'string'` to narrow the resulting type. When errors are more complex or `ResultType` is also a string, use an object with a `success` property, e.g. `() => { success: true, bytecode: Uint8Array } | { success: false, errors: ErrorType[] }`.
31+
- Exception: errors that can never happen during correct usage of a function may be either 1) detected by type checking or 2) thrown. For example, if a function always expects 32-byte Uint8Array inputs (like `encodeCashAddress`), an incorrectly sized Uint8Array implies incorrect usage of the function by the implementing application. Such implementation errors should ideally be detected at development time and never occur at runtime.
3132
- **test the import** – when importing modules within the library, aim to import from a sibling or a sibling of the closest mutual parent module (this helps to avoid import cycles), rather than importing from a higher-level export (like `lib.ts`). When importing modules within test files, always import directly from the top-level `lib.ts` file – this ensures that intended public functionality is available and working as expected. (Note: this is also enforced by our eslint configuration.)
3233
- **try the formatting utilities** – especially when writing tests for large, complex objects, the `stringify` and `stringifyTestVector` utilities can save you a lot of time.
33-
34-
## Areas for Improvement
35-
36-
### Thinner WASM Implementations/Imports
37-
38-
One area where we could improve in terms of the [`flexibility` Design Goal](../README.md#Design-Goals) (`Consumers should be able to import only the functionality they need`) is with WASM implementations.
39-
40-
While WASM can't currently be tree-shaken (in [the "live code inclusion" sense](https://medium.com/@Rich_Harris/tree-shaking-versus-dead-code-elimination-d3765df85c80)), we might be able to provide thinned-down versions of different WASM modules for use-cases which don't require the full module.
41-
42-
Our method for instantiating and wrapping the WASM module also prevents tree-shaking of unused wrapper code. (And breaks slightly from a purely-functional programming style.)
43-
44-
It may be better to instead provide each wrapper method as an individually exported function (which accepts a WASM object of the proper shape, as well as the parameters it currently accepts). E.g. rather than creating an object full of methods like:
45-
46-
```
47-
wasm.method(param, param)
48-
```
49-
50-
We would use pure-looking methods which accept the WASM object (fundamentally, you can't get much purer when using WASM):
51-
52-
```
53-
methodWasm(wasm, param, param)
54-
```

.github/ISSUE_TEMPLATE.md

Whitespace-only changes.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

.github/workflows/benchmark.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Libauth Benchmarks
2+
on:
3+
push:
4+
branches:
5+
- v2
6+
7+
permissions:
8+
contents: write
9+
deployments: write
10+
11+
jobs:
12+
benchmark:
13+
name: Run Benchmarks
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
with:
18+
submodules: 'true'
19+
- name: Setup node
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: 16
23+
- name: Run benchmark
24+
run: yarn && yarn bench
25+
- name: Push benchmark result to gh-pages
26+
uses: benchmark-action/github-action-benchmark@3d3bca03e83647895ef4f911fa57de3c7a391aaf
27+
with:
28+
name: Benchmark.js Benchmark
29+
tool: 'benchmarkjs'
30+
output-file-path: bench.log
31+
github-token: ${{ secrets.GITHUB_TOKEN }}
32+
auto-push: true
33+
# Show alert with commit comment on detecting possible performance regression
34+
alert-threshold: '200%'
35+
comment-on-alert: true
36+
fail-on-alert: true
37+
alert-comment-cc-users: '@bitjson'

0 commit comments

Comments
 (0)