Skip to content

fix(deps): Replace deleted go-bip39 dependency with a local copy - #463

Closed
gojuukaze wants to merge 3 commits into
solana-foundation:mainfrom
gojuukaze:replace_bip39
Closed

fix(deps): Replace deleted go-bip39 dependency with a local copy#463
gojuukaze wants to merge 3 commits into
solana-foundation:mainfrom
gojuukaze:replace_bip39

Conversation

@gojuukaze

Copy link
Copy Markdown

Summary

This PR replaces the dependency on the deleted github.com/tyler-smith/go-bip39 repository with a local copy.

Motivation

The original repository is no longer available. As a result, fetching dependencies fails when:

  • using direct module download (GOPROXY=direct), or
  • the module is not already cached by the configured Go proxy.

This makes the project impossible to build in those environments.

Changes

  • Added a local copy of the go-bip39 package under bip39/.
  • Updated imports to reference the local package instead of the deleted upstream repository.

@greptile-apps

greptile-apps Bot commented Jul 9, 2026

Copy link
Copy Markdown

Greptile Summary

This PR vendors the deleted github.com/tyler-smith/go-bip39 package as a local copy under bip39/, fixing build failures in environments that use GOPROXY=direct or lack a populated proxy cache. All import sites (mnemonic.go, ae_key.go, elgamal_secret.go) are updated to reference the new in-module path, and the upstream entry is removed from go.mod/go.sum.

  • New bip39/ package: A near-verbatim copy of the upstream go-bip39 library, with wordlists bundled under bip39/wordlists/. Import path changed to github.com/gagliardetto/solana-go/bip39/wordlists.
  • Import updates: mnemonic.go, ae_key.go, and elgamal_secret.go each swap github.com/tyler-smith/go-bip39 for the local package; the public API surface (IsMnemonicValid, NewSeed) is unchanged so callers need no further modification.
  • Dependency cleanup: github.com/tyler-smith/go-bip39 removed from go.mod and go.sum; no new external dependencies are introduced since golang.org/x/crypto (needed for pbkdf2) was already a direct dependency.

Confidence Score: 5/5

Safe 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

Filename Overview
bip39/bip39.go Verbatim copy of the upstream go-bip39 core. Import path updated to local wordlists sub-package. Inherits the upstream's unguarded global wordList/wordMap state and a typo in ErrInvalidMnemonic (both already flagged in prior review threads). Logic is otherwise faithful to the original.
mnemonic.go Import swapped from tyler-smith/go-bip39 to the new local package. API usage (IsMnemonicValid, NewSeed) unchanged; no functional impact.
go.mod tyler-smith/go-bip39 removed. No new external dependencies added; golang.org/x/crypto (needed by pbkdf2) was already a direct require.
programs/token-2022/zkencryption/ae_key.go Import updated to local bip39 package. Only bip39.NewSeed is used; API is identical.
programs/token-2022/zkencryption/elgamal_secret.go Import updated to local bip39 package. Only bip39.NewSeed is used; API is identical.
bip39/bip39_test.go Test file copied from upstream with updated import. Covers NewMnemonic, EntropyFromMnemonic, IsMnemonicValid, and seed vectors.

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
Loading
%%{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
Loading

Reviews (2): Last reviewed commit: "Merge branch 'replace_bip39' of github.c..." | Re-trigger Greptile

Comment thread bip39/bip39.go

var (
// ErrInvalidMnemonic is returned when trying to use a malformed mnemonic.
ErrInvalidMnemonic = errors.New("Invalid mnenomic")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Suggested change
ErrInvalidMnemonic = errors.New("Invalid mnenomic")
ErrInvalidMnemonic = errors.New("Invalid mnemonic")

Comment thread bip39/bip39.go
Comment on lines +46 to +50
// wordList is the set of words to use
wordList []string

// wordMap is a reverse lookup map for wordList
wordMap map[string]int

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Comment thread bip39/bip39.go
Comment on lines +1 to +5
// 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Missing LICENSE attribution

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!

@gojuukaze gojuukaze closed this Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant