Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Design Doc: Flexibility in choosing a cryptography provider #646

Open
Shaptic opened this issue Jul 17, 2023 · 0 comments
Open

Design Doc: Flexibility in choosing a cryptography provider #646

Shaptic opened this issue Jul 17, 2023 · 0 comments

Comments

@Shaptic
Copy link
Contributor

Shaptic commented Jul 17, 2023

Parent Epic: stellar/js-stellar-sdk#848

This issue is scoped to the item about sodium-native et al. being a problematic dependency.

Design Idea: Crypto provider flexibility

What if we made an assumption about the existence of a shim layer that was then provided to us as a polyfill? For example, we would write,

// in e.g. src/keypair.js
import { CryptoProvider } from 'stellar-crypto';

// the following can be assumed to exist:
CryptoProvider.sign
CryptoProvider.verify
CryptoProvider.generate

Then, the user can either leverage existing providers (sodium-native, tweetnacl, etc.) or implement their own shim layer:

mkdir -p ~/projects/stellar-crypto-shim
cd ~/projects/stellar-crypto-shim
npm -y init
touch index.js
yarn link 'stellar-crypto'
// index.js
import { createSecretKey } from 'crypto'; // node's crypto lib

// 
// This is just to demonstrate how the shim layer would work, not provide a
// secure implementation of a shim via Node's `crypto` library. DON'T USE THIS.
//

function generate() {
    // https://nodejs.org/api/crypto.html#cryptocreatesecretkeykey-encoding
    const { publicKey, privateKey } = generateKeyPairSync('ed25519')
    return [publicKey, privateKey]
}
// etc.

and run

yarn link 'stellar-crypto'

Just as easily, they could use sodium-native as a shim, tweetnacl, noble, etc. The onus of choice would be on them, though we could provide some defaults, e.g.

yarn add @stellar/sdk @stellar/sdk-sodium-shim
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

No branches or pull requests

2 participants
@Shaptic and others