Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(js): use buffer instead of text-decoder #170

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should not be removed I think?

Otherwise when you run yarn install it will automatically download the binaries, which you may not want

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the React Native Example to be used without building it locally it is required now. It is not optimal, agreed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd fail if we increase the native binary version. As the CI will then try to install the native binary, but it doesn't exist yet

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being required to build it locally doesn't seem like a bad thing to me, is there a reason we don't want to do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason right now is that cross only allows to be ran on a Linux host which would make building the application for Android on macOS or Windows impossible. With a better example app we could add something where you specify the platform and you can choose to only build the application for iOS which would make it work on macOS.

# 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