Skip to content

Commit

Permalink
Bump jsbt helpers 0.3.0. Add build:release script.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Jan 18, 2025
1 parent 8a7a927 commit a5a20ea
Show file tree
Hide file tree
Showing 13 changed files with 686 additions and 124 deletions.
56 changes: 7 additions & 49 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,14 @@ name: Publish release
on:
release:
types: [created]
workflow_dispatch:
jobs:
publish-jsr:
name: Publish to JSR.io
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2 # v4
- run: npm install -g jsr
- run: jsr publish
publish-npm:
name: Publish to NPM
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2 # v4
- uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4
with:
node-version: 22
registry-url: 'https://registry.npmjs.org'
cache: npm
- run: npm ci
- run: npm run build
- run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
standalone:
name: Upload files to GitHub Releases
runs-on: ubuntu-latest
test-js:
name: 'jsbt v0.3.0' # Should match commit below
uses: paulmillr/jsbt/.github/workflows/test-js.yml@973650a225c0344aa5f993a6cd63835a262077e9
with:
build-path: test/build
secrets:
NPM_PUBLISH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2 # v4
- uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4
with:
node-version: 22
registry-url: 'https://registry.npmjs.org'
cache: npm
- run: npm ci
- run: npm run build
- run: |
cd build
npm ci
npm run build:release
cd ..
- run: gh release upload ${{ github.event.release.tag_name }} build/`npx jsbt outfile`
env:
GH_TOKEN: ${{ github.token }}
4 changes: 2 additions & 2 deletions .github/workflows/test-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ on:
- pull_request
jobs:
test-js:
name: "JS v0.2.2" # v0.2.2 == commit below
uses: paulmillr/jsbt/.github/workflows/test-js.yml@986dbfea9667eeb0e81bf606cbe9ed169fea89b2
name: 'jsbt v0.3.0' # Should match commit below
uses: paulmillr/jsbt/.github/workflows/test-js.yml@973650a225c0344aa5f993a6cd63835a262077e9
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
node_modules
/build/micro-eth-signer.js
/lib
/index.js
/index.d.ts
/test/fixtures/*
/test/fixtures/*
/test/build
90 changes: 72 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
"module": "lib/esm/index.js",
"types": "lib/index.d.ts",
"dependencies": {
"@scure/base": "~1.1.5",
"@scure/base": "~1.2.1",
"@scure/btc-signer": "~1.3.2",
"enquirer": "2.4.1",
"micro-packed": "~0.6.2"
"micro-packed": "~0.7.1"
},
"devDependencies": {
"@noble/curves": "^1.4.0",
"@paulmillr/jsbt": "0.1.0",
"@noble/curves": "^1.8.0",
"@paulmillr/jsbt": "0.3.0",
"@types/node": "20.12.7",
"micro-bmark": "0.3.1",
"micro-should": "0.5.0",
Expand All @@ -29,7 +29,7 @@
},
"scripts": {
"build": "tsc && tsc -p tsconfig.cjs.json",
"build:release": "cd build; npm run build:release",
"build:release": "npx jsbt esbuild test/build",
"lint": "prettier --check src",
"format": "prettier --write src",
"test": "node test/index.js",
Expand Down
12 changes: 6 additions & 6 deletions src/cbor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as P from "micro-packed";
import { utils } from "@scure/btc-signer";
import * as P from "micro-packed";

type Bytes = Uint8Array;

Expand Down Expand Up @@ -58,7 +58,7 @@ const cborUint = P.wrap({
if (value < 24)
return INFO.encodeStream(
w,
typeof value === "bigint" ? Number(value) : value,
typeof value === "bigint" ? Number(value) : value
);
for (const ai in CBOR_LIMITS) {
const [limit, intCoder, _] = CBOR_LIMITS[ai];
Expand Down Expand Up @@ -120,13 +120,13 @@ const cborArrLength = <T>(inner: P.CoderType<T>): P.CoderType<T[]> =>
const cborLength = <T>(
fn: (len: P.Length) => P.CoderType<T>,
// Indefinity-length strings accept other elements with different types, we validate that later
def: P.CoderType<any>,
def: P.CoderType<any>
): P.CoderType<T | T[]> =>
P.wrap({
encodeStream(w, value: T | T[]) {
if (Array.isArray(value))
throw new Error(
"cbor/length: encoding indefinite-length strings not supported",
"cbor/length: encoding indefinite-length strings not supported"
);
const bytes = fn(null).encode(value);
if (bytes.length < 24) {
Expand Down Expand Up @@ -217,7 +217,7 @@ const cborValue: P.CoderType<CborValue> = P.mappedTag(P.bits(3), {
simple: [7, cborSimple], // Floating-point numbers and simple values, as well as the "break" stop code
});

export const CBOR = P.apply(cborValue, {
export const CBOR: P.CoderType<any> = P.apply(cborValue, {
encode(from: CborValue): any {
let value = from.data;
if (from.TAG === "bytes") {
Expand Down Expand Up @@ -251,7 +251,7 @@ export const CBOR = P.apply(cborValue, {
(from.data as any).map(([k, v]: [any, any]) => [
this.encode(k),
this.encode(v),
]),
])
);
}
if (from.TAG === "tag") throw new Error("not implemented");
Expand Down
Loading

0 comments on commit a5a20ea

Please sign in to comment.