Skip to content

Commit 4a9d2b2

Browse files
committed
build changes: Switch to pure ESM, switch tests to ts.
1 parent 51ca624 commit 4a9d2b2

File tree

15 files changed

+114
-108
lines changed

15 files changed

+114
-108
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ on:
44
types: [created]
55
jobs:
66
release-js:
7-
name: 'jsbt v0.4.1'
8-
uses: paulmillr/jsbt/.github/workflows/release.yml@2318b9efe24831b4bd4cadf720c96f071c69c64d
7+
name: 'jsbt v0.4.2' # Should match commit below
8+
uses: paulmillr/jsbt/.github/workflows/release.yml@5194a28c9f94ad504090fe037fe6efb41e5b8964
99
with:
1010
build-path: test/build
1111
# slow-types: false

.github/workflows/test-js.yml

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

.github/workflows/test-ts.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: Run TS tests
2+
on:
3+
- push
4+
- pull_request
5+
jobs:
6+
test-ts:
7+
name: 'jsbt v0.4.2' # Should match commit below
8+
uses: paulmillr/jsbt/.github/workflows/test-ts.yml@5194a28c9f94ad504090fe037fe6efb41e5b8964

.gitignore

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
build/
2-
node_modules/
3-
/lib
1+
node_modules
2+
*.tgz
43
/*.js
5-
/*.d.ts
6-
/*.map
4+
*.js.map
5+
*.d.ts
6+
*.d.ts.map
7+
/test/build
8+
/test/compiled

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,12 @@ Audited & minimal JS implementation of sr25519 cryptography for Polkadot.
3131
3232
> `deno add jsr:@scure/sr25519`
3333
34-
> `deno doc jsr:@scure/sr25519` # command-line documentation
35-
36-
37-
```ts
38-
import * as sr25519 from '@scure/sr25519';
39-
```
40-
4134
We support all major platforms and runtimes.
4235

4336
### Basic
4437

4538
```ts
39+
import * as sr25519 from '@scure/sr25519';
4640
const signature = sr25519.sign(pair.secretKey, msg);
4741
const isValid = sr25519.verify(msg, polkaSig, pair.publicKey);
4842
const secretKey = sr25519.secretFromSeed(seed);

package-lock.json

Lines changed: 30 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,35 @@
33
"version": "0.2.0",
44
"description": "Audited & minimal implementation of sr25519 (polkadot) cryptography, with Merlin and Strobe",
55
"files": [
6-
"lib",
6+
"index.js",
7+
"index.js.map",
8+
"index.d.ts",
9+
"index.d.ts.map",
710
"index.ts"
811
],
9-
"exports": {
10-
".": {
11-
"import": "./lib/esm/index.js",
12-
"require": "./lib/index.js"
13-
}
14-
},
1512
"dependencies": {
16-
"@noble/curves": "2.0.0-beta.2",
17-
"@noble/hashes": "2.0.0-beta.4"
13+
"@noble/curves": "2.0.0-beta.3",
14+
"@noble/hashes": "2.0.0-beta.5"
1815
},
1916
"devDependencies": {
20-
"@paulmillr/jsbt": "0.4.1",
21-
"micro-bmark": "0.4.1",
17+
"@paulmillr/jsbt": "0.4.2",
18+
"micro-bmark": "0.4.2",
2219
"micro-should": "0.5.3",
23-
"prettier": "3.5.2",
24-
"typescript": "5.8.3"
25-
},
26-
"main": "index.js",
27-
"module": "index.js",
28-
"types": "index.d.ts",
29-
"type": "module",
30-
"sideEffects": false,
31-
"author": "Paul Miller (https://paulmillr.com)",
32-
"license": "MIT",
33-
"homepage": "https://github.com/paulmillr/scure-sr25519",
34-
"repository": {
35-
"type": "git",
36-
"url": "git+https://github.com/paulmillr/scure-sr25519.git"
20+
"prettier": "3.6.2",
21+
"typescript": "5.9.2"
3722
},
3823
"scripts": {
3924
"build": "tsc",
4025
"build:release": "npx --no @paulmillr/jsbt esbuild test/build",
41-
"bench": "cd test/benchmark; npm i; node index.js",
42-
"lint": "prettier --check index.ts test/*.test.js",
43-
"format": "prettier --write index.ts test/*.test.js",
26+
"bench": "cd test/benchmark; npm i; node index.ts",
27+
"format": "prettier --write index.ts 'test/**/*.{js,ts}'",
4428
"test": "node test/index.ts",
4529
"test:bun": "bun test/index.ts",
46-
"test:deno": "deno --allow-env --allow-read test/index.ts"
30+
"test:deno": "deno --allow-env --allow-read test/index.ts",
31+
"test:node20": "cd test; npx tsc; node compiled/test/index.js"
32+
},
33+
"engines": {
34+
"node": ">= 20.19.0"
4735
},
4836
"keywords": [
4937
"sr25519",
@@ -55,5 +43,17 @@
5543
"ristretto",
5644
"ed25519"
5745
],
58-
"funding": "https://paulmillr.com/funding/"
59-
}
46+
"homepage": "https://paulmillr.com/noble/#scure",
47+
"funding": "https://paulmillr.com/funding/",
48+
"repository": {
49+
"type": "git",
50+
"url": "git+https://github.com/paulmillr/scure-sr25519.git"
51+
},
52+
"type": "module",
53+
"main": "index.js",
54+
"module": "index.js",
55+
"types": "index.d.ts",
56+
"sideEffects": false,
57+
"author": "Paul Miller (https://paulmillr.com)",
58+
"license": "MIT"
59+
}

test/benchmark/index.js renamed to test/benchmark/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { mark } from 'micro-bmark';
21
import { hexToBytes, utf8ToBytes } from '@noble/hashes/utils';
3-
import * as sr25519 from '../../lib/esm/index.js';
42
import * as polka from '@polkadot/util-crypto';
53
import { deepStrictEqual } from 'assert';
4+
import { mark } from 'micro-bmark';
5+
import * as sr25519 from '../../index.ts';
66

77
async function compare(title, runs, kinds) {
88
for (let [name, fn] of Object.entries(kinds)) {
@@ -34,7 +34,7 @@ async function compare(title, runs, kinds) {
3434
if (BENCH) {
3535
await compare('secretFromSeed', 100_000, {
3636
wasm: () => polka.sr25519PairFromSeed(selfSeed),
37-
micro: () => sr25519.secretFromSeed(selfSeed),
37+
scure: () => sr25519.secretFromSeed(selfSeed),
3838
});
3939
}
4040

@@ -48,7 +48,7 @@ async function compare(title, runs, kinds) {
4848
if (BENCH) {
4949
await compare('getSharedSecret', 1_000, {
5050
wasm: () => polka.sr25519Agreement(skSelf, pubOther),
51-
micro: () => sr25519.getSharedSecret(skSelf, pubOther),
51+
scure: () => sr25519.getSharedSecret(skSelf, pubOther),
5252
});
5353
}
5454

@@ -63,7 +63,7 @@ async function compare(title, runs, kinds) {
6363
if (BENCH) {
6464
await compare('HDKD.secretHard', 50_000, {
6565
wasm: () => polka.sr25519DeriveHard(pair, cc),
66-
micro: () => sr25519.HDKD.secretHard(skSelf, cc),
66+
scure: () => sr25519.HDKD.secretHard(skSelf, cc),
6767
});
6868
}
6969

@@ -77,7 +77,7 @@ async function compare(title, runs, kinds) {
7777
if (BENCH) {
7878
await compare('HDKD.secretSoft', 1_000, {
7979
wasm: () => polka.sr25519DeriveSoft(pair, cc),
80-
micro: () => sr25519.HDKD.secretSoft(skSelf, cc),
80+
scure: () => sr25519.HDKD.secretSoft(skSelf, cc),
8181
});
8282
}
8383

@@ -89,7 +89,7 @@ async function compare(title, runs, kinds) {
8989
if (BENCH) {
9090
await compare('HDKD.publicSoft', 1_000, {
9191
wasm: () => polka.sr25519DerivePublic(pubSelf, cc),
92-
micro: () => sr25519.HDKD.publicSoft(pubSelf, cc),
92+
scure: () => sr25519.HDKD.publicSoft(pubSelf, cc),
9393
});
9494
}
9595

@@ -104,11 +104,11 @@ async function compare(title, runs, kinds) {
104104
if (BENCH) {
105105
await compare('sign', 1_000, {
106106
wasm: () => polka.sr25519Sign(msg, pair),
107-
micro: () => sr25519.sign(pair.secretKey, msg),
107+
scure: () => sr25519.sign(pair.secretKey, msg),
108108
});
109109
await compare('verify', 1_000, {
110110
wasm: () => polka.sr25519Verify(msg, nobleSig, pair.publicKey),
111-
micro: () => sr25519.verify(msg, nobleSig, pair.publicKey),
111+
scure: () => sr25519.verify(msg, nobleSig, pair.publicKey),
112112
});
113113
}
114114
// VRF
@@ -123,11 +123,11 @@ async function compare(title, runs, kinds) {
123123
if (BENCH) {
124124
await compare('vrfSign', 1_000, {
125125
wasm: () => polka.sr25519VrfSign(msg, pair),
126-
micro: () => sr25519.vrf.sign(msg, pair.secretKey),
126+
scure: () => sr25519.vrf.sign(msg, pair.secretKey),
127127
});
128128
await compare('vrfVerify', 1_000, {
129129
wasm: () => polka.sr25519VrfVerify(msg, polkaVrfSig, pair.publicKey),
130-
micro: () => sr25519.vrf.verify(msg, nobleVrfSig, pair.publicKey),
130+
scure: () => sr25519.vrf.verify(msg, nobleVrfSig, pair.publicKey),
131131
});
132132
}
133133
})();

test/benchmark/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
"devDependencies": {
1515
"@polkadot/util-crypto": "13.5.1"
1616
}
17-
}
17+
}

test/build/package-lock.json

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)