From 739513a775ed276e334a14da1a4785c3038a92ac Mon Sep 17 00:00:00 2001 From: yougotwill Date: Tue, 29 Oct 2024 14:00:04 +1100 Subject: [PATCH 1/3] feat: added support for blinding method to sign requests --- libsession-util | 2 +- src/blinding/blinding.hpp | 42 ++++++++++++++++++++++++++++++++++-- types/blinding/blinding.d.ts | 12 +++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/libsession-util b/libsession-util index 0193c36..e73c72a 160000 --- a/libsession-util +++ b/libsession-util @@ -1 +1 @@ -Subproject commit 0193c36e0dad461385d6407a00f33b7314e6d740 +Subproject commit e73c72a771a0580f4d57b704c4e6b1c93a5d13de diff --git a/src/blinding/blinding.hpp b/src/blinding/blinding.hpp index 88d4f62..b906c28 100644 --- a/src/blinding/blinding.hpp +++ b/src/blinding/blinding.hpp @@ -19,7 +19,7 @@ class BlindingWrapper : public Napi::ObjectWrap { public: BlindingWrapper(const Napi::CallbackInfo& info) : Napi::ObjectWrap{info} { throw std::invalid_argument( - "BlindingWrapper is all static and don't need to be constructed"); + "BlindingWrapper is all static and doesn't need to be constructed"); } static void Init(Napi::Env env, Napi::Object exports) { @@ -32,11 +32,14 @@ class BlindingWrapper : public Napi::ObjectWrap { "blindVersionPubkey", static_cast( napi_writable | napi_configurable)), + StaticMethod<&BlindingWrapper::blindVersionSignRequest>( + "blindVersionSignRequest", + static_cast( + napi_writable | napi_configurable)), StaticMethod<&BlindingWrapper::blindVersionSign>( "blindVersionSign", static_cast( napi_writable | napi_configurable)), - }); } @@ -67,6 +70,41 @@ class BlindingWrapper : public Napi::ObjectWrap { }); }; + static Napi::Value blindVersionSignRequest(const Napi::CallbackInfo& info) { + return wrapResult(info, [&] { + assertInfoLength(info, 1); + assertIsObject(info[0]); + auto obj = info[0].As(); + + if (obj.IsEmpty()) + throw std::invalid_argument("blindVersionSignRequest received empty"); + + assertIsUInt8Array(obj.Get("ed25519SecretKey")); + auto ed25519_secret_key = toCppBuffer( + obj.Get("ed25519SecretKey"), "blindVersionSignRequest.ed25519SecretKey"); + + assertIsNumber(obj.Get("sigTimestampSeconds")); + auto sig_timestamp = toCppInteger( + obj.Get("sigTimestampSeconds"), + "blindVersionSignRequest.sigTimestampSeconds", + false); + + assertIsUInt8Array(obj.Get("sigMethod")); + auto sig_method = + toCppBuffer(obj.Get("sigMethod"), "blindVersionSignRequest.sigMethod"); + + assertIsUInt8Array(obj.Get("sigPath")); + auto sig_path = toCppBuffer(obj.Get("sigPath"), "blindVersionSignRequest.sigPath"); + + assertIsUInt8ArrayOrNull(obj.Get("sigBody")); + auto sig_body = + maybeNonemptyBuffer(obj.Get("sigBody"), "blindVersionSignRequest.sigBody"); + + return session::blind_version_sign_request( + ed25519_secret_key, sig_timestamp, sig_method, sig_path, sig_body); + }); + }; + static Napi::Value blindVersionSign(const Napi::CallbackInfo& info) { return wrapResult(info, [&] { assertInfoLength(info, 1); diff --git a/types/blinding/blinding.d.ts b/types/blinding/blinding.d.ts index 5c0ad23..30b5b20 100644 --- a/types/blinding/blinding.d.ts +++ b/types/blinding/blinding.d.ts @@ -8,6 +8,16 @@ declare module 'libsession_util_nodejs' { */ ed25519SecretKey: Uint8Array; }) => string; + blindVersionSignRequest: (opts: { + /** + * len 64: ed25519 secretKey with pubkey + */ + ed25519SecretKey: Uint8Array; + sigTimestampSeconds: number; + sigMethod: Uint8Array; + sigPath: Uint8Array; + sigBody: Uint8Array | null; + }) => Uint8Array; blindVersionSign: (opts: { /** * len 64: ed25519 secretKey with pubkey @@ -24,6 +34,7 @@ declare module 'libsession_util_nodejs' { */ export class BlindingWrapperNode { public static blindVersionPubkey: BlindingWrapper['blindVersionPubkey']; + public static blindVersionSignRequest: BlindingWrapper['blindVersionSignRequest']; public static blindVersionSign: BlindingWrapper['blindVersionSign']; } @@ -34,5 +45,6 @@ declare module 'libsession_util_nodejs' { */ export type BlindingActionsType = | MakeActionCall + | MakeActionCall | MakeActionCall; } From f6ab45063954492071ac9b09ff4ef88d245323d5 Mon Sep 17 00:00:00 2001 From: yougotwill Date: Fri, 22 Nov 2024 11:16:15 +1100 Subject: [PATCH 2/3] feat: change path and method to strings update libsession_util to latest dev --- libsession-util | 2 +- src/blinding/blinding.hpp | 8 ++++---- types/blinding/blinding.d.ts | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libsession-util b/libsession-util index e73c72a..c29c934 160000 --- a/libsession-util +++ b/libsession-util @@ -1 +1 @@ -Subproject commit e73c72a771a0580f4d57b704c4e6b1c93a5d13de +Subproject commit c29c93457eb6abfdb9e13af378cc67a2dc68115d diff --git a/src/blinding/blinding.hpp b/src/blinding/blinding.hpp index b906c28..200a619 100644 --- a/src/blinding/blinding.hpp +++ b/src/blinding/blinding.hpp @@ -89,12 +89,12 @@ class BlindingWrapper : public Napi::ObjectWrap { "blindVersionSignRequest.sigTimestampSeconds", false); - assertIsUInt8Array(obj.Get("sigMethod")); + assertIsString(obj.Get("sigMethod")); auto sig_method = - toCppBuffer(obj.Get("sigMethod"), "blindVersionSignRequest.sigMethod"); + toCppString(obj.Get("sigMethod"), "blindVersionSignRequest.sigMethod"); - assertIsUInt8Array(obj.Get("sigPath")); - auto sig_path = toCppBuffer(obj.Get("sigPath"), "blindVersionSignRequest.sigPath"); + assertIsString(obj.Get("sigPath")); + auto sig_path = toCppString(obj.Get("sigPath"), "blindVersionSignRequest.sigPath"); assertIsUInt8ArrayOrNull(obj.Get("sigBody")); auto sig_body = diff --git a/types/blinding/blinding.d.ts b/types/blinding/blinding.d.ts index 30b5b20..5e2dba0 100644 --- a/types/blinding/blinding.d.ts +++ b/types/blinding/blinding.d.ts @@ -14,8 +14,8 @@ declare module 'libsession_util_nodejs' { */ ed25519SecretKey: Uint8Array; sigTimestampSeconds: number; - sigMethod: Uint8Array; - sigPath: Uint8Array; + sigMethod: string; + sigPath: string; sigBody: Uint8Array | null; }) => Uint8Array; blindVersionSign: (opts: { From 7c017136df1166ab2f91a16d858ef56d305de421 Mon Sep 17 00:00:00 2001 From: yougotwill Date: Fri, 22 Nov 2024 11:52:47 +1100 Subject: [PATCH 3/3] fix: add missing args to assertions --- src/blinding/blinding.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/blinding/blinding.hpp b/src/blinding/blinding.hpp index 02cc32e..39cc242 100644 --- a/src/blinding/blinding.hpp +++ b/src/blinding/blinding.hpp @@ -18,8 +18,7 @@ class BlindingWrapper : public Napi::ObjectWrap { public: BlindingWrapper(const Napi::CallbackInfo& info) : Napi::ObjectWrap{info} { - throw std::invalid_argument( - "BlindingWrapper is static and doesn't need to be constructed"); + throw std::invalid_argument("BlindingWrapper is static and doesn't need to be constructed"); } static void Init(Napi::Env env, Napi::Object exports) { @@ -79,11 +78,13 @@ class BlindingWrapper : public Napi::ObjectWrap { if (obj.IsEmpty()) throw std::invalid_argument("blindVersionSignRequest received empty"); - assertIsUInt8Array(obj.Get("ed25519SecretKey")); + assertIsUInt8Array( + obj.Get("ed25519SecretKey"), "blindVersionSignRequest.ed25519SecretKey"); auto ed25519_secret_key = toCppBuffer( obj.Get("ed25519SecretKey"), "blindVersionSignRequest.ed25519SecretKey"); - assertIsNumber(obj.Get("sigTimestampSeconds")); + assertIsNumber( + obj.Get("sigTimestampSeconds"), "blindVersionSignRequest.sigTimestampSeconds"); auto sig_timestamp = toCppInteger( obj.Get("sigTimestampSeconds"), "blindVersionSignRequest.sigTimestampSeconds",