Skip to content

Commit

Permalink
chore: Update klave sdk version
Browse files Browse the repository at this point in the history
  • Loading branch information
Gosu14 committed Nov 12, 2024
1 parent 0eb8521 commit 1a6b2b9
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 34 deletions.
21 changes: 14 additions & 7 deletions apps/klave-basic-wallet/klave/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ export function sign(input: SignInput): string {
if(key)
{
emit(`Signing message: ${input.message} - with key: ${input.keyName}`);
let signatureU8 = key.sign(input.message);
if (signatureU8) {
let signatureBytes = convertToUint8Array(signatureU8);
signature = b64encode(signatureBytes);
emit(`Signature: ${signature}`);
}
let signatureResult = key.sign(String.UTF8.encode(input.message));
if(!signatureResult.data) {
emit("ERROR: Signature could not be generated");
return signature;
}
let signatureBytes = Uint8Array.wrap(signatureResult.data as ArrayBuffer);
signature = b64encode(signatureBytes);
emit(`Signature: ${signature}`);
}
return signature;
}
Expand All @@ -48,7 +50,12 @@ export function verify(input: VerifyInput): boolean {
if (key) {
emit(`Verifying message: ${input.message} - with signature: ${input.signature}`);
let signatureAsBytes = b64decode(input.signature);
return key.verify(input.message, convertToU8Array(signatureAsBytes));
let verificationResult = key.verify(String.UTF8.encode(input.message), signatureAsBytes.buffer);
if (!verificationResult.data) {
emit("ERROR: Verification failed");
return false;
}
return (verificationResult.data as Crypto.SignatureVerification).isValid;
}
return false;
}
24 changes: 20 additions & 4 deletions apps/klave-basic-wallet/wallet/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ export class Key {
}

create(description: string, type: string): boolean {
this.id = b64encode(convertToUint8Array(Crypto.getRandomValues(64)));
let random = Crypto.getRandomValues(64);
if(!random) {
revert("ERROR: Random values could not be generated");
return false;
}
this.id = b64encode(random);
revert(`ERROR: Key type '${this.type}' is not supported`);
this.description = description;
this.type = type;
this.owner = Context.get('sender');
Expand Down Expand Up @@ -98,8 +104,13 @@ export class Key {
if (!KeyAES) {
revert("ERROR: Key not found");
return "";
}
return b64encode(convertToUint8Array(KeyAES.encrypt(message)));
}
let cipherResult = KeyAES.encrypt(String.UTF8.encode(message));
if (!cipherResult.data) {
revert("ERROR: Encryption failed");
return "";
}
return b64encode(Uint8Array.wrap(cipherResult.data as ArrayBuffer));
}

decrypt(cypher: string): string {
Expand All @@ -112,6 +123,11 @@ export class Key {
revert("ERROR: Key not found");
return "";
}
return KeyAES.decrypt(convertToU8Array(b64decode(cypher)));
let cleartTextResult = KeyAES.decrypt(b64decode(cypher).buffer);
if (!cleartTextResult.data) {
revert("ERROR: Decryption failed");
return "";
}
return String.UTF8.decode(cleartTextResult.data as ArrayBuffer);
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"build": "stac ."
},
"devDependencies": {
"@klave/sdk": "0.12.0",
"@klave/sdk": "0.13.0",
"as-base64": "0.2.0",
"assemblyscript": "^0.27.26",
"path-complete-extname": "1.0.0",
Expand Down
97 changes: 75 additions & 22 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
# yarn lockfile v1


"@klave/[email protected]":
version "0.9.21"
resolved "https://registry.yarnpkg.com/@klave/as-json/-/as-json-0.9.21.tgz#cbcb8dab1e972a9ed235729b2e7e4c5c003e2b95"
integrity sha512-bdI6ixZF2u2YaYFCzl+iUJVMbQde9XNtlzl5TiHDPxA+LRNHPstqNtpkhZDg/2/igjmCoRAr/uKnJXMEysGuOA==
dependencies:
as-virtual "^0.2.0"

"@klave/as-json@^0.8.2":
version "0.8.2"
resolved "https://registry.yarnpkg.com/@klave/as-json/-/as-json-0.8.2.tgz#1c5e499f0e92fdcabf04700a59e3d7fd119864bb"
Expand All @@ -24,30 +31,19 @@
typescript "^5.4.4"
uuid "^9.0.1"

"@klave/sdk@0.12.0":
version "0.12.0"
resolved "https://registry.yarnpkg.com/@klave/sdk/-/sdk-0.12.0.tgz#6fcedd51a4727eb8689f381c363edcf33414a52f"
integrity sha512-qdeMw2hJrAE+r5j5+XEPWY+wEh1k2RlBCIvh/OTuTsHn78PvcxqdOCZp/yxP/skaJGHjlpJut/z1aTeiiXoJpQ==
"@klave/sdk@0.13.0-dev.23":
version "0.13.0-dev.23"
resolved "https://registry.yarnpkg.com/@klave/sdk/-/sdk-0.13.0-dev.23.tgz#76485718b5985ce153a09f95b34120c23d730d08"
integrity sha512-hKEVOpqW47t04NPwvMzxLya3YfgDOZHUqtpSkYSFkF4IYlDA9Les74rDWu5q7JGE2GRO5N5mHM+n0W9kbDSM/g==
dependencies:
"@klave/as-json" "^0.8.2"
"@klave/as-json" "0.9.21"
"@klave/compiler" "0.5.0"
"@swc/helpers" "0.5.11"
"@total-typescript/ts-reset" "^0.5.1"
as-base64 "0.2.0"
assemblyscript "^0.27.27"
chalk "^4.1.2"
chalk "^4.0.0"
esbuild-node-externals "1.14.0"
fs-extra "^11.2.0"
path-complete-extname "1.0.0"
serialize-error "8.1.0"
uuid "^9.0.1"
zod "^3.23.5"

"@swc/[email protected]":
version "0.5.11"
resolved "https://registry.yarnpkg.com/@swc/helpers/-/helpers-0.5.11.tgz#5bab8c660a6e23c13b2d23fcd1ee44a2db1b0cb7"
integrity sha512-YNlnKRWF2sVojTpIyzwou9XoTNbzbzONwRhOoniEioF1AtaitTvVZblaQRrAzChWQ1bLYyYSWzM18y4WwgzJ+A==
dependencies:
tslib "^2.4.0"
zod "3.23.8"

"@total-typescript/ts-reset@^0.5.1":
version "0.5.1"
Expand Down Expand Up @@ -81,6 +77,11 @@ as-virtual@^0.1.9:
resolved "https://registry.yarnpkg.com/as-virtual/-/as-virtual-0.1.9.tgz#57ad771b8ba4216143d70174d0b40ee494313945"
integrity sha512-R1nR7TT0KcROL/TxSXmiX2Q+7CgUMrjT/y9IP07StStqWs32KT2mpadJNF//yHWRaIJWe6atqTqO0JzsdhkPcQ==

as-virtual@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/as-virtual/-/as-virtual-0.2.0.tgz#f498e22ba5291a61f7ce40cfd940e68c3dc587ab"
integrity sha512-zI+8VwD6BPUtXrxs4R7v2N+59OAIBRwiiv9nGIMwcQ/w/lspyaualMqM7yok3jMRglKqLkfOx+dCJimeflEJcA==

assemblyscript@^0.27.26, assemblyscript@^0.27.27:
version "0.27.27"
resolved "https://registry.yarnpkg.com/assemblyscript/-/assemblyscript-0.27.27.tgz#a3ebab9ab1f7e5ed3e88d7e81d04be57874f15bf"
Expand All @@ -94,7 +95,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-116.0.0-nightly.20240114.tgz#ad8bfbde77d4cb4715b93997114eefc30f45155b"
integrity sha512-0GZrojJnuhoe+hiwji7QFaL3tBlJoA+KFUN7ouYSDGZLSo9CKM8swQX8n/UcbR0d1VuZKU+nhogNzv423JEu5A==

chalk@^4.1.2:
chalk@^4.0.0:
version "4.1.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
Expand All @@ -114,6 +115,22 @@ color-name@~1.1.4:
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==

[email protected]:
version "1.14.0"
resolved "https://registry.yarnpkg.com/esbuild-node-externals/-/esbuild-node-externals-1.14.0.tgz#fc2950c67a068dc2b538fd1381ad7d8e20a6f54d"
integrity sha512-jMWnTlCII3cLEjR5+u0JRSTJuP+MgbjEHKfwSIAI41NgLQ0ZjfzjchlbEn0r7v2u5gCBMSEYvYlkO7GDG8gG3A==
dependencies:
find-up "^5.0.0"
tslib "^2.4.1"

find-up@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/find-up/-/find-up-5.0.0.tgz#4c92819ecb7083561e4f4a240a86be5198f536fc"
integrity sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==
dependencies:
locate-path "^6.0.0"
path-exists "^4.0.0"

fs-extra@^11.2.0:
version "11.2.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.2.0.tgz#e70e17dfad64232287d01929399e0ea7c86b0e5b"
Expand Down Expand Up @@ -142,6 +159,13 @@ jsonfile@^6.0.1:
optionalDependencies:
graceful-fs "^4.1.6"

locate-path@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-6.0.0.tgz#55321eb309febbc59c4801d931a72452a681d286"
integrity sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==
dependencies:
p-locate "^5.0.0"

lodash.clonedeep@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef"
Expand All @@ -152,11 +176,30 @@ long@^5.2.1:
resolved "https://registry.yarnpkg.com/long/-/long-5.2.3.tgz#a3ba97f3877cf1d778eccbcb048525ebb77499e1"
integrity sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==

p-limit@^3.0.2:
version "3.1.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-3.1.0.tgz#e1daccbe78d0d1388ca18c64fea38e3e57e3706b"
integrity sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==
dependencies:
yocto-queue "^0.1.0"

p-locate@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-5.0.0.tgz#83c8315c6785005e3bd021839411c9e110e6d834"
integrity sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==
dependencies:
p-limit "^3.0.2"

[email protected]:
version "1.0.0"
resolved "https://registry.yarnpkg.com/path-complete-extname/-/path-complete-extname-1.0.0.tgz#f889985dc91000c815515c0bfed06c5acda0752b"
integrity sha512-CVjiWcMRdGU8ubs08YQVzhutOR5DEfO97ipRIlOGMK5Bek5nQySknBpuxVAVJ36hseTNs+vdIcv57ZrWxH7zvg==

path-exists@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3"
integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==

[email protected]:
version "8.1.0"
resolved "https://registry.yarnpkg.com/serialize-error/-/serialize-error-8.1.0.tgz#3a069970c712f78634942ddd50fbbc0eaebe2f67"
Expand All @@ -176,7 +219,12 @@ ts-mixer@^6.0.2:
resolved "https://registry.yarnpkg.com/ts-mixer/-/ts-mixer-6.0.4.tgz#1da39ceabc09d947a82140d9f09db0f84919ca28"
integrity sha512-ufKpbmrugz5Aou4wcr5Wc1UUFWOLhq+Fm6qa6P0w0K5Qw2yhaUoiWszhCVuNQyNwrlGiscHOmqYoAox1PtvgjA==

tslib@^2.4.0, tslib@^2.6.2:
tslib@^2.4.1:
version "2.8.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.1.tgz#612efe4ed235d567e8aba5f2a5fab70280ade83f"
integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==

tslib@^2.6.2:
version "2.6.2"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"
integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==
Expand Down Expand Up @@ -209,7 +257,12 @@ visitor-as@^0.11.4:
lodash.clonedeep "^4.5.0"
ts-mixer "^6.0.2"

zod@^3.22.4, zod@^3.23.5:
yocto-queue@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==

[email protected], zod@^3.22.4:
version "3.23.8"
resolved "https://registry.yarnpkg.com/zod/-/zod-3.23.8.tgz#e37b957b5d52079769fb8097099b592f0ef4067d"
integrity sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==

0 comments on commit 1a6b2b9

Please sign in to comment.