mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2024-12-05 02:10:18 +00:00
Do not use DataView (#28)
This commit is contained in:
parent
c65c0afbee
commit
052a8a7f24
4
.github/workflows/js_sdk_ci.yml
vendored
4
.github/workflows/js_sdk_ci.yml
vendored
@ -22,9 +22,9 @@ jobs:
|
||||
- uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.npm
|
||||
key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
|
||||
key: ${{ runner.os }}-v1-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-node-${{ matrix.node-version }}
|
||||
${{ runner.os }}-v1-node-${{ matrix.node-version }}
|
||||
|
||||
- name: Setup Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { createLocalClient } from '../connection';
|
||||
import {subscribeForErrors} from "../../api";
|
||||
|
||||
describe('== AIR suite', () => {
|
||||
it('check init_peer_id', async function () {
|
||||
@ -59,7 +60,7 @@ describe('== AIR suite', () => {
|
||||
it('call script without ttl', async function () {
|
||||
// arrange
|
||||
const client = await createLocalClient();
|
||||
const script = `(call %init_peer_id% ("" "") [""])`;
|
||||
const script = `(call %init_peer_id% ("op" "identity") [""])`;
|
||||
|
||||
// act
|
||||
const promise = client.sendScript(script, undefined, 1);
|
||||
|
@ -147,12 +147,11 @@ export async function build(
|
||||
timestamp: currentTime,
|
||||
ttl: ttl,
|
||||
script: script,
|
||||
// TODO: sign particle
|
||||
signature: '',
|
||||
data: Buffer.from([]),
|
||||
};
|
||||
|
||||
particle.signature = await signParticle(peerId, particle);
|
||||
|
||||
return particle;
|
||||
}
|
||||
|
||||
@ -187,33 +186,6 @@ export function parseParticle(str: string): ParticleDto {
|
||||
};
|
||||
}
|
||||
|
||||
export function canonicalBytes(particle: ParticleDto) {
|
||||
let peerIdBuf = Buffer.from(particle.init_peer_id, 'utf8');
|
||||
let idBuf = Buffer.from(particle.id, 'utf8');
|
||||
|
||||
let tsArr = new ArrayBuffer(8);
|
||||
new DataView(tsArr).setBigUint64(0, BigInt(particle.timestamp));
|
||||
let tsBuf = Buffer.from(tsArr);
|
||||
|
||||
let ttlArr = new ArrayBuffer(4);
|
||||
new DataView(ttlArr).setUint32(0, particle.ttl);
|
||||
let ttlBuf = Buffer.from(ttlArr);
|
||||
|
||||
let scriptBuf = Buffer.from(particle.script, 'utf8');
|
||||
|
||||
return Buffer.concat([peerIdBuf, idBuf, tsBuf, ttlBuf, scriptBuf]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign a particle with a private key from peerId.
|
||||
*/
|
||||
export async function signParticle(peerId: PeerId, particle: ParticleDto): Promise<string> {
|
||||
let bufToSign = canonicalBytes(particle);
|
||||
|
||||
let signature = await peerId.privKey.sign(bufToSign);
|
||||
return encode(signature);
|
||||
}
|
||||
|
||||
export function genUUID() {
|
||||
return uuidv4();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user