Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.

Commit 052a8a7

Browse files
authored
Do not use DataView (#28)
1 parent c65c0af commit 052a8a7

File tree

3 files changed

+5
-32
lines changed

3 files changed

+5
-32
lines changed

.github/workflows/js_sdk_ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ jobs:
2222
- uses: actions/cache@v2
2323
with:
2424
path: ~/.npm
25-
key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
25+
key: ${{ runner.os }}-v1-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
2626
restore-keys: |
27-
${{ runner.os }}-node-${{ matrix.node-version }}
27+
${{ runner.os }}-v1-node-${{ matrix.node-version }}
2828
2929
- name: Setup Node.js ${{ matrix.node-version }}
3030
uses: actions/setup-node@v1

src/__test__/unit/air.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createLocalClient } from '../connection';
2+
import {subscribeForErrors} from "../../api";
23

34
describe('== AIR suite', () => {
45
it('check init_peer_id', async function () {
@@ -59,7 +60,7 @@ describe('== AIR suite', () => {
5960
it('call script without ttl', async function () {
6061
// arrange
6162
const client = await createLocalClient();
62-
const script = `(call %init_peer_id% ("" "") [""])`;
63+
const script = `(call %init_peer_id% ("op" "identity") [""])`;
6364

6465
// act
6566
const promise = client.sendScript(script, undefined, 1);

src/internal/particle.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,11 @@ export async function build(
147147
timestamp: currentTime,
148148
ttl: ttl,
149149
script: script,
150+
// TODO: sign particle
150151
signature: '',
151152
data: Buffer.from([]),
152153
};
153154

154-
particle.signature = await signParticle(peerId, particle);
155-
156155
return particle;
157156
}
158157

@@ -187,33 +186,6 @@ export function parseParticle(str: string): ParticleDto {
187186
};
188187
}
189188

190-
export function canonicalBytes(particle: ParticleDto) {
191-
let peerIdBuf = Buffer.from(particle.init_peer_id, 'utf8');
192-
let idBuf = Buffer.from(particle.id, 'utf8');
193-
194-
let tsArr = new ArrayBuffer(8);
195-
new DataView(tsArr).setBigUint64(0, BigInt(particle.timestamp));
196-
let tsBuf = Buffer.from(tsArr);
197-
198-
let ttlArr = new ArrayBuffer(4);
199-
new DataView(ttlArr).setUint32(0, particle.ttl);
200-
let ttlBuf = Buffer.from(ttlArr);
201-
202-
let scriptBuf = Buffer.from(particle.script, 'utf8');
203-
204-
return Buffer.concat([peerIdBuf, idBuf, tsBuf, ttlBuf, scriptBuf]);
205-
}
206-
207-
/**
208-
* Sign a particle with a private key from peerId.
209-
*/
210-
export async function signParticle(peerId: PeerId, particle: ParticleDto): Promise<string> {
211-
let bufToSign = canonicalBytes(particle);
212-
213-
let signature = await peerId.privKey.sign(bufToSign);
214-
return encode(signature);
215-
}
216-
217189
export function genUUID() {
218190
return uuidv4();
219191
}

0 commit comments

Comments
 (0)