fix(deps): Replace deleted go-bip39 dependency with a local copy - #463
fix(deps): Replace deleted go-bip39 dependency with a local copy#463gojuukaze wants to merge 3 commits into
Conversation
Greptile SummaryThis PR vendors the deleted
Confidence Score: 5/5Safe to merge. The change is a pure vendoring of a deleted upstream package with no functional modifications to the BIP-39 logic. The local copy is a faithful reproduction of the deleted upstream package. All three import sites are correctly updated, no new external dependencies are introduced, and the public API surface is identical to what callers already rely on. Previously identified concerns (unguarded globals, missing LICENSE, error message typo) are pre-existing and unchanged by this PR. bip39/bip39.go carries known pre-existing concerns from prior review threads; no new issues were found in this PR. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[mnemonic.go] -->|bip39.IsMnemonicValid\nbip39.NewSeed| B[bip39/bip39.go]
C[ae_key.go] -->|bip39.NewSeed| B
D[elgamal_secret.go] -->|bip39.NewSeed| B
B -->|wordlists.English| E[bip39/wordlists/english.go]
B -->|other wordlists| F[bip39/wordlists/...]
B -->|pbkdf2.Key| G[golang.org/x/crypto/pbkdf2]
H[github.com/tyler-smith/go-bip39\n❌ DELETED upstream] -. was .- A
H -. was .- C
H -. was .- D
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[mnemonic.go] -->|bip39.IsMnemonicValid\nbip39.NewSeed| B[bip39/bip39.go]
C[ae_key.go] -->|bip39.NewSeed| B
D[elgamal_secret.go] -->|bip39.NewSeed| B
B -->|wordlists.English| E[bip39/wordlists/english.go]
B -->|other wordlists| F[bip39/wordlists/...]
B -->|pbkdf2.Key| G[golang.org/x/crypto/pbkdf2]
H[github.com/tyler-smith/go-bip39\n❌ DELETED upstream] -. was .- A
H -. was .- C
H -. was .- D
Reviews (2): Last reviewed commit: "Merge branch 'replace_bip39' of github.c..." | Re-trigger Greptile |
|
|
||
| var ( | ||
| // ErrInvalidMnemonic is returned when trying to use a malformed mnemonic. | ||
| ErrInvalidMnemonic = errors.New("Invalid mnenomic") |
There was a problem hiding this comment.
The error message contains a typo inherited from the original
go-bip39 package: "mnenomic" should be "mnemonic". Since this is now a vendored local copy, it's a good opportunity to fix it. Any callers comparing error strings directly (rather than using errors.Is) would see the misspelling.
| ErrInvalidMnemonic = errors.New("Invalid mnenomic") | |
| ErrInvalidMnemonic = errors.New("Invalid mnemonic") |
| // wordList is the set of words to use | ||
| wordList []string | ||
|
|
||
| // wordMap is a reverse lookup map for wordList | ||
| wordMap map[string]int |
There was a problem hiding this comment.
Unprotected global mutable state
wordList and wordMap are package-level variables with no mutex. A concurrent call to SetWordList while NewMnemonic, EntropyFromMnemonic, or IsMnemonicValid are in flight will cause a data race — the reader iterates over wordMap/wordList while the writer replaces them. This is inherited from the upstream package, but since SetWordList is a public API and tests import this package, a sync.RWMutex guard would eliminate the race entirely.
| // Package bip39 is the Golang implementation of the BIP39 spec. | ||
| // | ||
| // The official BIP39 spec can be found at | ||
| // https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki | ||
| package bip39 |
There was a problem hiding this comment.
The bip39/ directory is a near-verbatim copy of github.com/tyler-smith/go-bip39, which is MIT-licensed. The MIT license requires that its copyright notice and permission notice be included in all copies. There is no LICENSE file (or copyright comment) in bip39/ or bip39/wordlists/, so the current state does not satisfy that attribution requirement.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Summary
This PR replaces the dependency on the deleted
github.com/tyler-smith/go-bip39repository with a local copy.Motivation
The original repository is no longer available. As a result, fetching dependencies fails when:
GOPROXY=direct), orThis makes the project impossible to build in those environments.
Changes
go-bip39package underbip39/.