ion-hash-js
A JavaScript implementation of the Ion Hash Specification.
License
This library is licensed under the Apache 2.0 License.
An implementation of Amazon Ion Hash for JavaScript.
[!docs](https://amzn.github.io/ion-hash-js/api)
Getting Started
This library is designed to work with Node 8/ES5/CommonJS.
Node
-
Add ion-hash-js to your dependencies using npm:
npm install --save ion-hash-js
-
Use the library to read an Ion value and generate an Ion hash:
import * as ion from 'ion-js';
import {cryptoIonHasherProvider, makeHashReader} from 'ion-hash-js';
let ionStr = '[1, 2, 3]';
let hashReader = makeHashReader(
ion.makeReader(ionStr),
cryptoIonHasherProvider('md5'));
hashReader.next();
hashReader.next();
let digest = hashReader.digest();
process.stdout.write('digest: ');
digest.forEach(b => {
process.stdout.write(('0' + ((b as number) & 0xFF).toString(16)).slice(-2) + ' ');
});
process.stdout.write('\n');
produces:
digest: 8f 3b f4 b1 93 5c f4 69 c9 c1 0c 31 52 4b 26 25
-
Use the library to write Ion data:
import * as ion from 'ion-js';
import {cryptoIonHasherProvider, makeHashWriter} from 'ion-hash-js';
let hashWriter = makeHashWriter(
ion.makeTextWriter(),
cryptoIonHasherProvider('md5'));
hashWriter.writeList();
hashWriter.writeInt(1);
hashWriter.writeInt(2);
hashWriter.writeInt(3);
hashWriter.endContainer();
let digest = hashWriter.digest();
process.stdout.write('digest: ');
digest.forEach(b => {
process.stdout.write(('0' + ((b as number) & 0xFF)
.toString(16)).slice(-2) + ' ');
});
process.stdout.write('\n');
produces:
digest: 8f 3b f4 b1 93 5c f4 69 c9 c1 0c 31 52 4b 26 25