mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-06-22 20:31:32 +00:00
Do not use DataView (#28)
This commit is contained in:
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
|
- uses: actions/cache@v2
|
||||||
with:
|
with:
|
||||||
path: ~/.npm
|
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: |
|
restore-keys: |
|
||||||
${{ runner.os }}-node-${{ matrix.node-version }}
|
${{ runner.os }}-v1-node-${{ matrix.node-version }}
|
||||||
|
|
||||||
- name: Setup Node.js ${{ matrix.node-version }}
|
- name: Setup Node.js ${{ matrix.node-version }}
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { createLocalClient } from '../connection';
|
import { createLocalClient } from '../connection';
|
||||||
|
import {subscribeForErrors} from "../../api";
|
||||||
|
|
||||||
describe('== AIR suite', () => {
|
describe('== AIR suite', () => {
|
||||||
it('check init_peer_id', async function () {
|
it('check init_peer_id', async function () {
|
||||||
@ -59,7 +60,7 @@ describe('== AIR suite', () => {
|
|||||||
it('call script without ttl', async function () {
|
it('call script without ttl', async function () {
|
||||||
// arrange
|
// arrange
|
||||||
const client = await createLocalClient();
|
const client = await createLocalClient();
|
||||||
const script = `(call %init_peer_id% ("" "") [""])`;
|
const script = `(call %init_peer_id% ("op" "identity") [""])`;
|
||||||
|
|
||||||
// act
|
// act
|
||||||
const promise = client.sendScript(script, undefined, 1);
|
const promise = client.sendScript(script, undefined, 1);
|
||||||
|
@ -147,12 +147,11 @@ export async function build(
|
|||||||
timestamp: currentTime,
|
timestamp: currentTime,
|
||||||
ttl: ttl,
|
ttl: ttl,
|
||||||
script: script,
|
script: script,
|
||||||
|
// TODO: sign particle
|
||||||
signature: '',
|
signature: '',
|
||||||
data: Buffer.from([]),
|
data: Buffer.from([]),
|
||||||
};
|
};
|
||||||
|
|
||||||
particle.signature = await signParticle(peerId, particle);
|
|
||||||
|
|
||||||
return 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() {
|
export function genUUID() {
|
||||||
return uuidv4();
|
return uuidv4();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user