Skip to content

Commit

Permalink
feat: use buffer instead of text-decoder
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <[email protected]>
  • Loading branch information
berendsliedrecht committed Aug 17, 2023
1 parent 1e67835 commit c0311e2
Show file tree
Hide file tree
Showing 23 changed files with 3,415 additions and 1,893 deletions.
3 changes: 3 additions & 0 deletions wrappers/javascript/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
'./tsconfig.eslint.json',
'./aries-askar-shared/tsconfig.json',
'./aries-askar-react-native/tsconfig.json',
'./aries-askar-react-native-app/tsconfig.json',
'./aries-askar-nodejs/tsconfig.json',
],
},
Expand All @@ -28,6 +29,7 @@ module.exports = {
project: [
'aries-askar-shared/tsconfig.json',
'aries-askar-react-native/tsconfig.json',
'aries-askar-react-native-app/tsconfig.json',
'aries-askar-nodejs/tsconfig.json',
],
alwaysTryTypes: true,
Expand All @@ -36,6 +38,7 @@ module.exports = {
project: [
'aries-askar-shared/tsconfig.json',
'aries-askar-react-native/tsconfig.json',
'aries-askar-react-native-app/tsconfig.json',
'aries-askar-nodejs/tsconfig.json',
],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
Expand Down
8 changes: 4 additions & 4 deletions wrappers/javascript/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ android/keystores/debug.keystore
.expo-shared/*

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

aries-askar-react-native-app/android
aries-askar-react-native-app/ios

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

# Example app
react-native-example

# Test
tmp
32 changes: 32 additions & 0 deletions wrappers/javascript/aries-askar-react-native-app/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"expo": {
"name": "aries-askar-react-native-app",
"slug": "aries-askar-react-native-app",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "org.hyperledger.ariesaskar.app"
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#ffffff"
},
"package": "org.hyperledger.ariesaskar.app"
},
"web": {
"favicon": "./assets/favicon.png"
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions wrappers/javascript/aries-askar-react-native-app/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const path = require('path')

const ariesAskarReactNative = require('../aries-askar-react-native/package.json')
const ariesAskarShared = require('../aries-askar-shared/package.json')

module.exports = function (api) {
api.cache(true)
return {
presets: ['babel-preset-expo'],
plugins: [
[
'module-resolver',
{
extensions: ['.tsx', '.ts', '.js', '.json'],
alias: {
[ariesAskarShared.name]: path.join(__dirname, '../aries-askar-shared', ariesAskarShared.source),
[ariesAskarReactNative.name]: path.join(
__dirname,
'../aries-askar-react-native',
ariesAskarReactNative.source
),
},
},
],
],
}
}
16 changes: 16 additions & 0 deletions wrappers/javascript/aries-askar-react-native-app/metro.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { getDefaultConfig } = require('expo/metro-config')
const path = require('path')

const projectRoot = __dirname
const workspaceRoot = path.resolve(projectRoot, '..')

const config = getDefaultConfig(projectRoot)

config.watchFolders = [workspaceRoot]
config.resolver.nodeModulesPaths = [
path.resolve(projectRoot, 'node_modules'),
path.resolve(workspaceRoot, 'node_modules'),
]
config.resolver.disableHierarchicalLookup = true

module.exports = config
24 changes: 24 additions & 0 deletions wrappers/javascript/aries-askar-react-native-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "aries-askar-react-native-app",
"version": "0.0.0",
"private": true,
"main": "./src/index.js",
"scripts": {
"prebuild": "expo prebuild",
"start": "expo start",
"android": "expo run:android",
"ios": "expo run:ios"
},
"dependencies": {
"@hyperledger/aries-askar-react-native": "*",
"expo": "~49.0.7",
"expo-splash-screen": "~0.20.5",
"expo-status-bar": "~1.6.0",
"react": "18.2.0",
"react-native": "0.72.3",
"react-native-get-random-values": "~1.9.0"
},
"devDependencies": {
"@babel/core": "^7.20.0"
}
}
21 changes: 21 additions & 0 deletions wrappers/javascript/aries-askar-react-native-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ariesAskar, Jwk } from '@hyperledger/aries-askar-react-native'
import { StatusBar } from 'expo-status-bar'
import { StyleSheet, Text, View } from 'react-native'

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
})

export const App = () => {
return (
<View style={styles.container}>
<StatusBar style="auto" />
<Text>Aries Askar version: {ariesAskar.version()}</Text>
</View>
)
}
7 changes: 7 additions & 0 deletions wrappers/javascript/aries-askar-react-native-app/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'react-native-get-random-values'

import { registerRootComponent } from 'expo'

import { App } from './App'

registerRootComponent(App)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"jsx": "react-native",
"types": ["react-native"]
}
}

This file was deleted.

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
11 changes: 4 additions & 7 deletions wrappers/javascript/aries-askar-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,19 @@
"publishConfig": {
"access": "public"
},
"files": [
"build"
],
"files": ["build"],
"scripts": {
"build": "yarn run clean && yarn run compile",
"clean": "rimraf -rf ./build",
"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)))
}
}
8 changes: 2 additions & 6 deletions wrappers/javascript/aries-askar-shared/src/crypto/Key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ariesAskar } from '../ariesAskar'
import { KeyMethod, keyAlgFromString } from '../enums'

import { Jwk } from './Jwk'
import { Buffer } from 'buffer'

export class Key {
private localKeyHandle: LocalKeyHandle
Expand Down Expand Up @@ -75,13 +76,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
8 changes: 2 additions & 6 deletions wrappers/javascript/aries-askar-shared/src/store/Entry.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from 'buffer'
import type { EntryListHandle } from '../crypto'

export type EntryObject = {
Expand Down Expand Up @@ -25,12 +26,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
6 changes: 1 addition & 5 deletions wrappers/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"private": true,
"license": "Apache-2.0",
"workspaces": {
"packages": [
"aries-askar-shared",
"aries-askar-react-native",
"aries-askar-nodejs"
]
"packages": ["aries-askar-shared", "aries-askar-react-native", "aries-askar-react-native-app", "aries-askar-nodejs"]
},
"scripts": {
"check-types": "yarn workspaces run tsc --noEmit -p tsconfig.json",
Expand Down
Loading

0 comments on commit c0311e2

Please sign in to comment.