Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ coverage
node_modules
*.rdb
*.log
dist
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,27 @@ BIP38 is a standard process to encrypt Bitcoin and crypto currency private keys

### Async methods

Async methods are available, but using them will be slower, but free up the event loop in intervals you choose.
Async methods are available. Using them will be slower but will free up the event loop. You can set `asyncTickInterval` in the scryptParams to control the maximum amount of time the function can block.

For benchmark results, please see the section in the README of the [scryptsy](https://github.com/cryptocoinjs/scryptsy/tree/395c3b09b21e06ea4a6cc2933e046c0984a414c5#benchmarks) library. Increasing the interval will decrease the performance hit, but increase the span between event loop free ups (UI drawing etc.) promiseInterval is the last optional parameter after scryptParams. There is no recommendation currently, as the performance trade off is app specific.
`N` is cpu/mem work factor (power of 2 e.g. 2**18)
`r` is block size (8 is common), fine-tunes sequential memory read size and performance
`p` is parallelization factor (1 is common)
`dkLen` is output key length in bytes e.g. 32.
`asyncTick` - (default: 10) max time in ms for which async function can block execution
`maxmem` - (default: `1024 ** 3 + 1024` aka 1GB+1KB). A limit that the app could use for scrypt
`onProgress` - callback function that would be executed for progress report

### API
### encrypt(buffer, compressed, passphrase[, progressCallback, scryptParams])

``` javascript
var bip38 = require('bip38')
var wif = require('wif')
import { encrypt } from "bip38"
import wif from "wif"

var myWifString = '5KN7MzqK5wt2TP1fQCYyHBtDrXdJuXbUzm4A9rKAteGu3Qi5CVR'
var decoded = wif.decode(myWifString)
const myWifString = '5KN7MzqK5wt2TP1fQCYyHBtDrXdJuXbUzm4A9rKAteGu3Qi5CVR'
const decoded = wif.decode(myWifString)

var encryptedKey = bip38.encrypt(decoded.privateKey, decoded.compressed, 'TestingOneTwoThree')
const encryptedKey = encrypt(decoded.privateKey, decoded.compressed, 'TestingOneTwoThree')
console.log(encryptedKey)
// => '6PRVWUbkzzsbcVac2qwfssoUJAN1Xhrg6bNk8J7Nzm5H7kxEbn2Nh2ZoGg'
```
Expand All @@ -54,12 +60,12 @@ console.log(encryptedKey)
### decrypt(encryptedKey, passphrase[, progressCallback, scryptParams])

``` javascript
var bip38 = require('bip38')
var wif = require('wif')
import { decrypt } from "bip38"
import wif from "wif"

var encryptedKey = '6PRVWUbkzzsbcVac2qwfssoUJAN1Xhrg6bNk8J7Nzm5H7kxEbn2Nh2ZoGg'
var decryptedKey = bip38.decrypt(encryptedKey, 'TestingOneTwoThree', function (status) {
console.log(status.percent) // will print the percent every time current increases by 1000
var decryptedKey = decrypt(encryptedKey, 'TestingOneTwoThree', function (percent) {
console.log(percent) // will print the percent every time current increases by 1000
})

console.log(wif.encode(0x80, decryptedKey.privateKey, decryptedKey.compressed))
Expand Down
10 changes: 10 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"formatter": {
"indentStyle": "space"
},
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
}
}
Binary file added bun.lockb
Binary file not shown.
11 changes: 11 additions & 0 deletions fixup
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cat >dist/cjs/package.json <<!EOF
{
"type": "commonjs"
}
!EOF

cat >dist/mjs/package.json <<!EOF
{
"type": "module"
}
!EOF
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO: types
Loading