Skip to content
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
45 changes: 42 additions & 3 deletions src/blinding/blinding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class BlindingWrapper : public Napi::ObjectWrap<BlindingWrapper> {

public:
BlindingWrapper(const Napi::CallbackInfo& info) : Napi::ObjectWrap<BlindingWrapper>{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) {
Expand All @@ -32,11 +31,14 @@ class BlindingWrapper : public Napi::ObjectWrap<BlindingWrapper> {
"blindVersionPubkey",
static_cast<napi_property_attributes>(
napi_writable | napi_configurable)),
StaticMethod<&BlindingWrapper::blindVersionSignRequest>(
"blindVersionSignRequest",
static_cast<napi_property_attributes>(
napi_writable | napi_configurable)),
StaticMethod<&BlindingWrapper::blindVersionSign>(
"blindVersionSign",
static_cast<napi_property_attributes>(
napi_writable | napi_configurable)),

});
}

Expand Down Expand Up @@ -67,6 +69,43 @@ class BlindingWrapper : public Napi::ObjectWrap<BlindingWrapper> {
});
};

static Napi::Value blindVersionSignRequest(const Napi::CallbackInfo& info) {
return wrapResult(info, [&] {
assertInfoLength(info, 1);
assertIsObject(info[0]);
auto obj = info[0].As<Napi::Object>();

if (obj.IsEmpty())
throw std::invalid_argument("blindVersionSignRequest received empty");

assertIsUInt8Array(
obj.Get("ed25519SecretKey"), "blindVersionSignRequest.ed25519SecretKey");
auto ed25519_secret_key = toCppBuffer(
obj.Get("ed25519SecretKey"), "blindVersionSignRequest.ed25519SecretKey");

assertIsNumber(
obj.Get("sigTimestampSeconds"), "blindVersionSignRequest.sigTimestampSeconds");
auto sig_timestamp = toCppInteger(
obj.Get("sigTimestampSeconds"),
"blindVersionSignRequest.sigTimestampSeconds",
false);

assertIsString(obj.Get("sigMethod"));
auto sig_method =
toCppString(obj.Get("sigMethod"), "blindVersionSignRequest.sigMethod");

assertIsString(obj.Get("sigPath"));
auto sig_path = toCppString(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);
Expand Down
12 changes: 12 additions & 0 deletions types/blinding/blinding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: string;
sigPath: string;
sigBody: Uint8Array | null;
}) => Uint8Array;
blindVersionSign: (opts: {
/**
* len 64: ed25519 secretKey with pubkey
Expand All @@ -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'];
}

Expand All @@ -34,5 +45,6 @@ declare module 'libsession_util_nodejs' {
*/
export type BlindingActionsType =
| MakeActionCall<BlindingWrapper, 'blindVersionPubkey'>
| MakeActionCall<BlindingWrapper, 'blindVersionSignRequest'>
| MakeActionCall<BlindingWrapper, 'blindVersionSign'>;
}
Loading