Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cybercongress/js-amino
Javascript implementation of the Amino encoding protocol
https://github.com/cybercongress/js-amino
amino blockchain cosmos cosmos-sdk gitcoin protobuf4 web3
Last synced: 3 months ago
JSON representation
Javascript implementation of the Amino encoding protocol
- Host: GitHub
- URL: https://github.com/cybercongress/js-amino
- Owner: cybercongress
- License: mit
- Archived: true
- Created: 2018-08-13T06:50:33.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-01T15:46:36.000Z (about 5 years ago)
- Last Synced: 2024-05-04T00:22:09.105Z (9 months ago)
- Topics: amino, blockchain, cosmos, cosmos-sdk, gitcoin, protobuf4, web3
- Language: JavaScript
- Homepage:
- Size: 323 KB
- Stars: 42
- Watchers: 11
- Forks: 10
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome - Amino
README
An Implementation of Amino for clients with Javascript
Current state: 1.0.0 First major public release
[![NPM](https://nodei.co/npm/js-amino.png)](https://npmjs.org/package/@cybercongress/js-amino)
For more information spec, please refer: https://github.com/tendermint/go-amino
## Features:
1. Encode and Decode simple types: ints 8/16/32/64, booleans, strings, bytes
2. Encode and Decode recursive Structs and Interfaces, Arrays
3. Encode simple Time data## Install From NPM:
Run `npm i js-amino`## Install From Source
1. Run `npm install`
## Running The Examples
1. `cd src/examples`
2. `go get`
3. Run examples, e. g. in Go: `go run string.go` and in JS `node string.js`## Running The Unit Test
1. Run `npm test`
## To Do:
1. Full support for Time encoding and decoding
2. More Unit test
3. Benchmarking## Gitcoin program
We want to pay you for your contribution! We constantly fund our issues on [gitcoin](https://gitcoin.co/profile/cybercongress) and attach good description for them with project state and user stories. We try to answer to comments regular in issues and in our [devChat](https://t.me/fuckgoogle).
## Our cosmos ecosystem initiative
## Usage (MsgMultiSend example)
```js
const {
Codec,
FieldOptions,
TypeFactory,
Utils,
Types,
WireTypes,
} = require('../index');let StdTx = TypeFactory.create('StdTx', [{
name: 'msg',
type: Types.ArrayInterface,
},
{
name: 'fee',
type: Types.Struct,
},
{
name: 'signatures',
type: Types.ArrayStruct,
},
{
name: 'memo',
type: Types.String,
},
]);let MsgMultiSend = TypeFactory.create('MsgMultiSend', [{
name: "inputs",
type: Types.ArrayStruct
},
{
name: "outputs",
type: Types.ArrayStruct
}
]);let Coin = TypeFactory.create('coin', [{
name: 'denom',
type: Types.String,
},
{
name: 'amount',
type: Types.String,
}
]);let Input = TypeFactory.create('input', [{
name: 'address',
type: Types.String,
},
{
name: 'coins',
type: Types.ArrayStruct,
}
]);let Output = TypeFactory.create('output', [{
name: 'address',
type: Types.String,
},
{
name: 'coins',
type: Types.ArrayStruct,
}
]);let Fee = TypeFactory.create('fee', [{
name: 'amount',
type: Types.ArrayStruct,
},
{
name: 'gas',
type: Types.Int64,
}
]);let PubKeySecp256k1 = TypeFactory.create('PubKeySecp256k1', [{
name: 's',
type: Types.ByteSlice,
}], Types.ByteSlice)let Signature = TypeFactory.create('signature', [{
name: 'pub_key',
type: Types.Interface,
},
{
name: 'signature',
type: Types.ByteSlice,
}
])let codec = new Codec();
codec.registerConcrete(new StdTx(), 'auth/StdTx', {});
codec.registerConcrete(new MsgMultiSend(), 'cosmos-sdk/MsgMultiSend', {});
codec.registerConcrete(new PubKeySecp256k1(), 'tendermint/PubKeySecp256k1', {});let coin = new Coin('cyb', "10000");
let addressFrom = [ 59,58,243,13,132,163,164,202,233,7,236,93,136,166,181,175,236,69,48,186 ]
let addressTo = [ 94,222,114,42,196,107,51,203,139,142,219,243,137,60,54,250,139,153,46,168 ]let input = new Input(addressFrom, [coin]);
let output = new Output(addressTo, [coin]);
let sendMultiMsg = new MsgMultiSend([input], [output]);
let fee = new Fee([new Coin('cyb', '0')], 200000);let pubKey = new PubKeySecp256k1([2,27,24,0,255,96,147,21,64,29,132,192,108,219,59,134,206,201,126,224,63,160,24,236,170,124,164,95,43,180,6,246,250]);
let signature = [165,76,109,61,53,129,190,147,52,224,34,106,235,208,224,36,190,25,204,36,226,129,97,109,35,130,217,228,144,106,10,134,14,183,95,252,219,235,22,92,37,53,3,89,111,173,12,158,146,71,82,113,236,241,170,121,217,20,236,23,131,35,80,29];let sig = new Signature(pubKey, signature);
let stdTx = new StdTx([sendMultiMsg], fee, [sig], 'elonmusk');let jsonTx = codec.marshalJson(stdTx);
let decodedDataTx = new StdTx();console.log("Binary stdTx:\n", (codec.marshalBinary(stdTx)).toString());
console.log("Json:\n", jsonTx);
codec.unMarshalBinary(codec.marshalBinary(stdTx), decodedDataTx);
console.log("Decoded data:\n", decodedDataTx.JsObject());
``````js
Binary stdTx:
220,1,240,98,93,238,10,80,194,104,154,209,10,36,10,20,59,58,243,13,132,163,164,202,233,7,236,93,136,166,181,175,236,69,48,186,18,12,10,3,99,121,98,18,5,49,48,48,48,48,18,36,10,20,94,222,114,42,196,107,51,203,139,142,219,243,137,60,54,250,139,153,46,168,18,12,10,3,99,121,98,18,5,49,48,48,48,48,18,14,10,8,10,3,99,121,98,18,1,48,16,192,154,12,26,106,10,38,235,90,233,135,33,2,27,24,0,255,96,147,21,64,29,132,192,108,219,59,134,206,201,126,224,63,160,24,236,170,124,164,95,43,180,6,246,250,18,64,165,76,109,61,53,129,190,147,52,224,34,106,235,208,224,36,190,25,204,36,226,129,97,109,35,130,217,228,144,106,10,134,14,183,95,252,219,235,22,92,37,53,3,89,111,173,12,158,146,71,82,113,236,241,170,121,217,20,236,23,131,35,80,29,34,8,101,108,111,110,109,117,115,107Json:
{"type":"auth/StdTx","value":{"msg":[{"type":"cosmos-sdk/MsgMultiSend","value":{"inputs":[{"address":[59,58,243,13,132,163,164,202,233,7,236,93,136,166,181,175,236,69,48,186],"coins":[{"denom":"cyb","amount":"10000"}]}],"outputs":[{"address":[94,222,114,42,196,107,51,203,139,142,219,243,137,60,54,250,139,153,46,168],"coins":[{"denom":"cyb","amount":"10000"}]}]}}],"fee":{"amount":[{"denom":"cyb","amount":"0"}],"gas":"200000"},"signatures":[{"pub_key":{"type":"tendermint/PubKeySecp256k1","value":"AhsYAP9gkxVAHYTAbNs7hs7JfuA/oBjsqnykXyu0Bvb6"},"signature":"pUxtPTWBvpM04CJq69DgJL4ZzCTigWFtI4LZ5JBqCoYOt1/82+sWXCU1A1lvrQyekkdScezxqnnZFOwXgyNQHQ=="}],"memo":"elonmusk"}}Decoded data:
{ msg: [ { inputs: [Array], outputs: [Array] } ],
fee: { amount: [ [Object] ], gas: 200000 },
signatures: [ { pub_key: [Array], signature: [Array] } ],
memo: 'elonmusk' }
```## Contributing Guide
Contribution are welcome! Please read this [guide](https://github.com/cybercongress/js-amino/blob/master/CONTRIBUTING.md) before contributing.
## Contributors
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
JungHwan Tony Yun
π»
TanNgocDo
π» π§
philipstanislaus
π
Ales Puchilo
π
Valery Litvin
π»
Cyber Admin
π
Ethan Frey
β οΈThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
## License
Code are licensed under [MIT](./LICENSE) license by [contributors](https://github.com/cybercongress/js-amino/graphs/contributors)