@tidecloak/js
Version:
TideCloak client side JS SDK
102 lines • 3.95 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlainSignatureFormat = exports.TestSignatureFormat = exports.TidecloakSettingsSignatureFormat = exports.AuthorizerSignatureFormat = exports.PublicKeySignatureFormat = exports.ClientURLSignatureFormat = exports.URLSignatureFormat = exports.TideSignatureFormat = void 0;
const index_js_1 = require("../index.js");
const Serialization_js_1 = require("../Serialization.js");
class TideSignatureFormat {
/**
* @param {string|Uint8Array} message
*/
constructor(message) {
this.Header = () => "=====TIDE_" + this.Name + ":" + this.Version + "_START=====\n";
this.Footer = () => "\n=====TIDE_" + this.Name + ":" + this.Version + "_END=====";
if (typeof (message) == 'string') {
this.Message = (0, Serialization_js_1.StringToUint8Array)(message);
}
else if (message instanceof Uint8Array) {
this.Message = message.slice();
}
else
throw Error("Unknown type provided");
}
/**
*
* @returns {Uint8Array}
*/
format() {
return (0, Serialization_js_1.ConcatUint8Arrays)([(0, Serialization_js_1.StringToUint8Array)(this.Header()), this.Message, (0, Serialization_js_1.StringToUint8Array)(this.Footer())]);
}
}
exports.TideSignatureFormat = TideSignatureFormat;
class URLSignatureFormat extends TideSignatureFormat {
constructor(message) {
super(message);
this.Name = "URL";
this.Version = "1";
}
}
exports.URLSignatureFormat = URLSignatureFormat;
class ClientURLSignatureFormat extends TideSignatureFormat {
constructor(message) {
super(message);
this.Name = "ClientURL";
this.Version = "1";
}
}
exports.ClientURLSignatureFormat = ClientURLSignatureFormat;
class PublicKeySignatureFormat extends TideSignatureFormat {
constructor(message) {
super(message);
this.Name = "PublicKey";
this.Version = "1";
}
}
exports.PublicKeySignatureFormat = PublicKeySignatureFormat;
class AuthorizerSignatureFormat extends TideSignatureFormat {
constructor(authflow, modelIds, authorizer) {
const authflow_b = (0, Serialization_js_1.StringToUint8Array)(authflow);
const models_b = modelIds.map(k => (0, Serialization_js_1.StringToUint8Array)(k));
const authorizer_pack = index_js_1.Serialization.CreateTideMemory(authflow_b, 8 + (4 * models_b.length) + authflow_b.length + models_b.reduce((sum, next) => sum + next.length, 0) + authorizer.length);
index_js_1.Serialization.WriteValue(authorizer_pack, 1, authorizer);
models_b.forEach((model, i) => {
index_js_1.Serialization.WriteValue(authorizer_pack, i + 2, model);
});
super(authorizer_pack);
this.Name = "Authorizer";
this.Version = "1";
}
format() {
return this.Message.slice();
}
}
exports.AuthorizerSignatureFormat = AuthorizerSignatureFormat;
class TidecloakSettingsSignatureFormat extends TideSignatureFormat {
constructor(message) {
super(message);
this.Name = "TidecloakSettings";
this.Version = "1";
}
}
exports.TidecloakSettingsSignatureFormat = TidecloakSettingsSignatureFormat;
class TestSignatureFormat extends TideSignatureFormat {
constructor(message) {
super(message);
this.Name = "TestMessage";
this.Version = "1";
}
}
exports.TestSignatureFormat = TestSignatureFormat;
class PlainSignatureFormat extends TideSignatureFormat {
/**
* WARNING: Only use this class if you are SURE that the data you are signing is ALREADY serialized in some form.
* @param {string|Uint8Array} message
*/
constructor(message) {
super(message);
}
format() {
return this.Message.slice();
}
}
exports.PlainSignatureFormat = PlainSignatureFormat;
//# sourceMappingURL=TideSignature.js.map