Skip to content

Commit

Permalink
Merge pull request #170 from berendsliedrecht/use-buffer
Browse files Browse the repository at this point in the history
feat(js): use buffer instead of text-decoder
  • Loading branch information
berendsliedrecht authored Sep 7, 2023
2 parents 76f4ae7 + 6c6f73c commit ee46c20
Show file tree
Hide file tree
Showing 12 changed files with 604 additions and 3,491 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Aries-Askar"

env:
RUST_VERSION: "1.65.0"
RUST_VERSION: "1.70.0"
CROSS_VERSION: "0.2.4"

concurrency:
Expand Down Expand Up @@ -393,7 +393,8 @@ jobs:
build-android:
name: Build library (Android)
needs: [checks]
# NB: RUST_VERSION must be 1.64+ here for lower NDK support
env:
RUST_VERSION: "1.67"

runs-on: ubuntu-latest

Expand Down
6 changes: 0 additions & 6 deletions wrappers/javascript/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,9 @@ android/keystores/debug.keystore
.expo/*
.expo-shared/*

# Native Libraries
aries-askar-react-native/ios/Frameworks
aries-askar-react-native/android/libs

# Test wallet
aries-askar-nodejs/tests/indy_wallet_sqlite_upgraded.db

# Example app
react-native-example

# Test
tmp
6 changes: 2 additions & 4 deletions wrappers/javascript/aries-askar-nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
"install": "node-pre-gyp install --target_arch=$(node scripts/arch.js) --target_platform=$(node scripts/platform.js)"
},
"devDependencies": {
"@types/2060.io__ffi-napi": "npm:@types/ffi-napi",
"@types/2060.io__ref-napi": "npm:@types/ref-napi",
"@types/jest": "^27.4.1",
"@types/node": "^17.0.31",
"@types/ref-array-di": "^1.2.3",
Expand All @@ -50,8 +48,8 @@
"dependencies": {
"@hyperledger/aries-askar-shared": "0.1.1",
"@mapbox/node-pre-gyp": "^1.0.10",
"@2060.io/ffi-napi": "4.0.5",
"@2060.io/ref-napi": "3.0.4",
"@2060.io/ffi-napi": "4.0.8",
"@2060.io/ref-napi": "3.0.6",
"node-cache": "^5.1.2",
"ref-array-di": "^1.2.2",
"ref-struct-di": "^1.1.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This is a placeholder file to prevent node-pre-gyp from installing the
# aries-askar binary when cloning this repository. It won't be published to
# NPM, meaning when you download this package from npm it will try to download
# the binary.
# the binary.
1 change: 0 additions & 1 deletion wrappers/javascript/aries-askar-react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"babel-plugin-module-resolver": "^4.0.0",
"prettier": "2.6.2",
"react": "17.0.2",
"react-native": "0.67.2",
"typescript": "4.5.5"
},
"peerDependencies": {
Expand Down
7 changes: 3 additions & 4 deletions wrappers/javascript/aries-askar-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
"compile": "tsc -p tsconfig.build.json",
"prepublishOnly": "yarn run build"
},
"dependencies": {
"buffer": "^6.0.3"
},
"devDependencies": {
"@types/fast-text-encoding": "^1.0.1",
"prettier": "^2.6.2",
"rimraf": "^3.0.2",
"typescript": "^4.5.5"
},
"dependencies": {
"fast-text-encoding": "^1.0.3"
}
}
10 changes: 3 additions & 7 deletions wrappers/javascript/aries-askar-shared/src/crypto/Jwk.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Buffer } from 'buffer'

export type JwkProps = {
kty: string
crv: string
Expand Down Expand Up @@ -30,12 +32,6 @@ export class Jwk {
}

public toUint8Array() {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
const encoder = new TextEncoder()
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
const encoded = encoder.encode(JSON.stringify(this)) as Uint8Array
return encoded
return Uint8Array.from(Buffer.from(JSON.stringify(this)))
}
}
9 changes: 3 additions & 6 deletions wrappers/javascript/aries-askar-shared/src/crypto/Key.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { LocalKeyHandle } from './handles'
import type { KeyAlgs, SigAlgs } from '../enums'

import { Buffer } from 'buffer'

import { ariesAskar } from '../ariesAskar'
import { KeyMethod, keyAlgFromString } from '../enums'

Expand Down Expand Up @@ -75,13 +77,8 @@ export class Key {
}

public get jwkSecret() {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
const decoder = new TextDecoder()
const secretBytes = ariesAskar.keyGetJwkSecret({ localKeyHandle: this.handle })
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
return Jwk.fromString(decoder.decode(secretBytes))
return Jwk.fromString(Buffer.from(secretBytes).toString())
}

public get jwkThumbprint() {
Expand Down
2 changes: 0 additions & 2 deletions wrappers/javascript/aries-askar-shared/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'fast-text-encoding'

export * from './error'
export * from './ariesAskar'
export * from './types'
Expand Down
9 changes: 3 additions & 6 deletions wrappers/javascript/aries-askar-shared/src/store/Entry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { EntryListHandle } from '../crypto'

import { Buffer } from 'buffer'

export type EntryObject = {
name: string
value: Record<string, unknown> | string
Expand All @@ -25,12 +27,7 @@ export class Entry {
}

public get value(): string {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
const decoder = new TextDecoder()
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
return decoder.decode(this.rawValue)
return Buffer.from(this.rawValue).toString()
}

private get rawValue() {
Expand Down
18 changes: 4 additions & 14 deletions wrappers/javascript/aries-askar-shared/src/store/Session.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { Key, SessionHandle } from '../crypto'
import type { KeyAlgs } from '../enums'

import { Buffer } from 'buffer'

import { ariesAskar } from '../ariesAskar'
import { EntryOperation } from '../enums/EntryOperation'
import { AriesAskarError } from '../error'
Expand Down Expand Up @@ -102,14 +104,8 @@ export class Session {
if (!this.handle) throw AriesAskarError.customError({ message: 'Cannot insert with a closed session' })
const serializedValue = typeof value === 'string' ? value : JSON.stringify(value)

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
const encoder = new TextEncoder()

await ariesAskar.sessionUpdate({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
value: new Uint8Array(encoder.encode(serializedValue)),
value: Uint8Array.from(Buffer.from(serializedValue)),
expiryMs,
tags,
name,
Expand All @@ -135,14 +131,8 @@ export class Session {
if (!this.handle) throw AriesAskarError.customError({ message: 'Cannot replace with a closed session' })
const serializedValue = typeof value === 'string' ? value : JSON.stringify(value)

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
const encoder = new TextEncoder()

await ariesAskar.sessionUpdate({
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
value: new Uint8Array(encoder.encode(serializedValue)),
value: Uint8Array.from(Buffer.from(serializedValue)),
expiryMs,
tags,
name,
Expand Down
Loading

0 comments on commit ee46c20

Please sign in to comment.