-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #686 from o1-labs/mina-signer/14
Publish the new mina-signer
- Loading branch information
Showing
20 changed files
with
185 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Mina Signer | ||
|
||
This is a NodeJS SDK that allows you to sign strings, payments, and delegations using Mina's key pairs for various specified networks. | ||
|
||
# Install | ||
|
||
```bash | ||
yarn add mina-signer | ||
# or with npm: | ||
npm install --save mina-signer | ||
``` | ||
|
||
# Usage | ||
|
||
```js | ||
import Client from 'mina-signer'; | ||
const client = new Client({ network: 'mainnet' }); | ||
|
||
// Generate keys | ||
let keypair = client.genKeys(); | ||
|
||
// Sign and verify message | ||
let signed = client.signMessage('hello', keypair); | ||
if (client.verifyMessage(signed)) { | ||
console.log('Message was verified successfully'); | ||
} | ||
|
||
// Sign and verify a payment | ||
let signedPayment = client.signPayment( | ||
{ | ||
to: keypair.publicKey, | ||
from: keypair.publicKey, | ||
amount: 1, | ||
fee: 1, | ||
nonce: 0, | ||
}, | ||
keypair.privateKey | ||
); | ||
if (client.verifyPayment(signedPayment)) { | ||
console.log('Payment was verified successfully'); | ||
} | ||
|
||
// Sign and verify a stake delegation | ||
const signedDelegation = client.signStakeDelegation( | ||
{ | ||
to: keypair.publicKey, | ||
from: keypair.publicKey, | ||
fee: '1', | ||
nonce: '0', | ||
}, | ||
keypair.privateKey | ||
); | ||
if (client.verifyStakeDelegation(signedDelegation)) { | ||
console.log('Delegation was verified successfully'); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
cp index.cjs dist/node/mina-signer/index.cjs | ||
cp index.d.ts dist/node/mina-signer/index.d.ts | ||
|
||
npx esbuild --bundle --minify dist/node/mina-signer/index.cjs --outfile=./dist/node/mina-signer/index.cjs --format=cjs --target=es2021 --platform=node --allow-overwrite=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
tsc -p ../../tsconfig.mina-signer-web.json | ||
node moveWebFiles.js | ||
npx esbuild --bundle --minify dist/tmp/mina-signer/MinaSigner.js --outfile=./dist/web/index.js --format=esm --target=es2021 | ||
npx rimraf dist/tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// this file is a wrapper for supporting commonjs imports | ||
|
||
let Client = require('./MinaSigner.js'); | ||
|
||
module.exports = Client.default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// this file is a wrapper for supporting types in both commonjs and esm projects | ||
|
||
import Client from './MinaSigner.js'; | ||
|
||
export = Client; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import glob from 'glob'; | ||
import { move } from 'fs-extra'; | ||
|
||
let webFiles = glob.sync('./dist/tmp/**/*.web.js'); | ||
|
||
await Promise.all( | ||
webFiles.map((file) => | ||
move(file, file.replace('.web.js', '.js'), { overwrite: true }) | ||
) | ||
); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "./tsconfig.mina-signer.json", | ||
"include": ["./src/mina-signer/MinaSigner.ts", "./src/**/*.web.ts"], | ||
"compilerOptions": { | ||
"outDir": "src/mina-signer/dist/tmp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters