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 Sep 5, 2023
1 parent 76f4ae7 commit 9fef5c4
Show file tree
Hide file tree
Showing 10 changed files with 597 additions and 3,486 deletions.
5 changes: 1 addition & 4 deletions wrappers/javascript/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,11 @@ 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

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

# Example app
react-native-example

# Test
tmp

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
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)))
}
}
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
Loading

0 comments on commit 9fef5c4

Please sign in to comment.