@tideorg/js 0.13.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +333 -0
- package/README.md +12 -0
- package/dist/Clients/ClientBase.d.ts +24 -0
- package/dist/Clients/ClientBase.d.ts.map +1 -0
- package/dist/Clients/ClientBase.js +160 -0
- package/dist/Clients/NetworkClient.d.ts +11 -0
- package/dist/Clients/NetworkClient.d.ts.map +1 -0
- package/dist/Clients/NetworkClient.js +68 -0
- package/dist/Clients/NodeClient.d.ts +34 -0
- package/dist/Clients/NodeClient.d.ts.map +1 -0
- package/dist/Clients/NodeClient.js +191 -0
- package/dist/Clients/VoucherClient.d.ts +8 -0
- package/dist/Clients/VoucherClient.d.ts.map +1 -0
- package/dist/Clients/VoucherClient.js +36 -0
- package/dist/Clients/index.d.ts +5 -0
- package/dist/Clients/index.d.ts.map +1 -0
- package/dist/Clients/index.js +20 -0
- package/dist/Contracts/BaseContract.d.ts +47 -0
- package/dist/Contracts/BaseContract.d.ts.map +1 -0
- package/dist/Contracts/BaseContract.js +153 -0
- package/dist/Contracts/GenericRealmAccessThresholdRoleContract.d.ts +8 -0
- package/dist/Contracts/GenericRealmAccessThresholdRoleContract.d.ts.map +1 -0
- package/dist/Contracts/GenericRealmAccessThresholdRoleContract.js +21 -0
- package/dist/Contracts/GenericResourceAccessThresholdRoleContract.d.ts +8 -0
- package/dist/Contracts/GenericResourceAccessThresholdRoleContract.d.ts.map +1 -0
- package/dist/Contracts/GenericResourceAccessThresholdRoleContract.js +21 -0
- package/dist/Contracts/index.d.ts +4 -0
- package/dist/Contracts/index.d.ts.map +1 -0
- package/dist/Contracts/index.js +19 -0
- package/dist/Cryptide/Components/BaseComponent.d.ts +56 -0
- package/dist/Cryptide/Components/BaseComponent.d.ts.map +1 -0
- package/dist/Cryptide/Components/BaseComponent.js +176 -0
- package/dist/Cryptide/Components/ComponentRegistry.d.ts +18 -0
- package/dist/Cryptide/Components/ComponentRegistry.d.ts.map +1 -0
- package/dist/Cryptide/Components/ComponentRegistry.js +39 -0
- package/dist/Cryptide/Components/Schemes/AES/AESScheme.d.ts +5 -0
- package/dist/Cryptide/Components/Schemes/AES/AESScheme.d.ts.map +1 -0
- package/dist/Cryptide/Components/Schemes/AES/AESScheme.js +20 -0
- package/dist/Cryptide/Components/Schemes/AES/index.d.ts +2 -0
- package/dist/Cryptide/Components/Schemes/AES/index.d.ts.map +1 -0
- package/dist/Cryptide/Components/Schemes/AES/index.js +17 -0
- package/dist/Cryptide/Components/Schemes/BaseScheme.d.ts +7 -0
- package/dist/Cryptide/Components/Schemes/BaseScheme.d.ts.map +1 -0
- package/dist/Cryptide/Components/Schemes/BaseScheme.js +23 -0
- package/dist/Cryptide/Components/Schemes/Ed25519/Ed25519Components.d.ts +52 -0
- package/dist/Cryptide/Components/Schemes/Ed25519/Ed25519Components.d.ts.map +1 -0
- package/dist/Cryptide/Components/Schemes/Ed25519/Ed25519Components.js +171 -0
- package/dist/Cryptide/Components/Schemes/Ed25519/Ed25519Scheme.d.ts +13 -0
- package/dist/Cryptide/Components/Schemes/Ed25519/Ed25519Scheme.d.ts.map +1 -0
- package/dist/Cryptide/Components/Schemes/Ed25519/Ed25519Scheme.js +71 -0
- package/dist/Cryptide/Components/Schemes/Ed25519/index.d.ts +3 -0
- package/dist/Cryptide/Components/Schemes/Ed25519/index.d.ts.map +1 -0
- package/dist/Cryptide/Components/Schemes/Ed25519/index.js +18 -0
- package/dist/Cryptide/Components/Schemes/SchemeRegistry.d.ts +3 -0
- package/dist/Cryptide/Components/Schemes/SchemeRegistry.d.ts.map +1 -0
- package/dist/Cryptide/Components/Schemes/SchemeRegistry.js +22 -0
- package/dist/Cryptide/Components/Schemes/index.d.ts +5 -0
- package/dist/Cryptide/Components/Schemes/index.d.ts.map +1 -0
- package/dist/Cryptide/Components/Schemes/index.js +20 -0
- package/dist/Cryptide/Components/index.d.ts +4 -0
- package/dist/Cryptide/Components/index.d.ts.map +1 -0
- package/dist/Cryptide/Components/index.js +19 -0
- package/dist/Cryptide/Ed25519.d.ts +106 -0
- package/dist/Cryptide/Ed25519.d.ts.map +1 -0
- package/dist/Cryptide/Ed25519.js +522 -0
- package/dist/Cryptide/Encryption/AES.d.ts +6 -0
- package/dist/Cryptide/Encryption/AES.d.ts.map +1 -0
- package/dist/Cryptide/Encryption/AES.js +76 -0
- package/dist/Cryptide/Encryption/DH.d.ts +4 -0
- package/dist/Cryptide/Encryption/DH.d.ts.map +1 -0
- package/dist/Cryptide/Encryption/DH.js +38 -0
- package/dist/Cryptide/Encryption/ElGamal.d.ts +12 -0
- package/dist/Cryptide/Encryption/ElGamal.d.ts.map +1 -0
- package/dist/Cryptide/Encryption/ElGamal.js +61 -0
- package/dist/Cryptide/Encryption/index.d.ts +4 -0
- package/dist/Cryptide/Encryption/index.d.ts.map +1 -0
- package/dist/Cryptide/Encryption/index.js +19 -0
- package/dist/Cryptide/Hashing/H2P.d.ts +6 -0
- package/dist/Cryptide/Hashing/H2P.d.ts.map +1 -0
- package/dist/Cryptide/Hashing/H2P.js +235 -0
- package/dist/Cryptide/Hashing/Hash.d.ts +8 -0
- package/dist/Cryptide/Hashing/Hash.d.ts.map +1 -0
- package/dist/Cryptide/Hashing/Hash.js +43 -0
- package/dist/Cryptide/Hashing/index.d.ts +3 -0
- package/dist/Cryptide/Hashing/index.d.ts.map +1 -0
- package/dist/Cryptide/Hashing/index.js +18 -0
- package/dist/Cryptide/Interpolation.d.ts +20 -0
- package/dist/Cryptide/Interpolation.d.ts.map +1 -0
- package/dist/Cryptide/Interpolation.js +68 -0
- package/dist/Cryptide/Math.d.ts +11 -0
- package/dist/Cryptide/Math.d.ts.map +1 -0
- package/dist/Cryptide/Math.js +81 -0
- package/dist/Cryptide/Serialization.d.ts +66 -0
- package/dist/Cryptide/Serialization.d.ts.map +1 -0
- package/dist/Cryptide/Serialization.js +517 -0
- package/dist/Cryptide/Signing/BlindSig.d.ts +10 -0
- package/dist/Cryptide/Signing/BlindSig.d.ts.map +1 -0
- package/dist/Cryptide/Signing/BlindSig.js +41 -0
- package/dist/Cryptide/Signing/EdDSA.d.ts +14 -0
- package/dist/Cryptide/Signing/EdDSA.d.ts.map +1 -0
- package/dist/Cryptide/Signing/EdDSA.js +67 -0
- package/dist/Cryptide/Signing/TideSignature.d.ts +54 -0
- package/dist/Cryptide/Signing/TideSignature.d.ts.map +1 -0
- package/dist/Cryptide/Signing/TideSignature.js +110 -0
- package/dist/Cryptide/Signing/index.d.ts +4 -0
- package/dist/Cryptide/Signing/index.d.ts.map +1 -0
- package/dist/Cryptide/Signing/index.js +19 -0
- package/dist/Cryptide/TideKey.d.ts +17 -0
- package/dist/Cryptide/TideKey.d.ts.map +1 -0
- package/dist/Cryptide/TideKey.js +84 -0
- package/dist/Cryptide/TideMemoryObjects.d.ts +4 -0
- package/dist/Cryptide/TideMemoryObjects.d.ts.map +1 -0
- package/dist/Cryptide/TideMemoryObjects.js +32 -0
- package/dist/Cryptide/index.d.ts +11 -0
- package/dist/Cryptide/index.d.ts.map +1 -0
- package/dist/Cryptide/index.js +28 -0
- package/dist/Flow/DecryptionFlows/dVVKDecryptionFlow.d.ts +16 -0
- package/dist/Flow/DecryptionFlows/dVVKDecryptionFlow.d.ts.map +1 -0
- package/dist/Flow/DecryptionFlows/dVVKDecryptionFlow.js +47 -0
- package/dist/Flow/DecryptionFlows/index.d.ts +2 -0
- package/dist/Flow/DecryptionFlows/index.d.ts.map +1 -0
- package/dist/Flow/DecryptionFlows/index.js +17 -0
- package/dist/Flow/EncryptionFlows/AuthorizedEncryptionFlow.d.ts +13 -0
- package/dist/Flow/EncryptionFlows/AuthorizedEncryptionFlow.d.ts.map +1 -0
- package/dist/Flow/EncryptionFlows/AuthorizedEncryptionFlow.js +183 -0
- package/dist/Flow/EncryptionFlows/PolicyAuthorizedEncryptionFlow.d.ts +57 -0
- package/dist/Flow/EncryptionFlows/PolicyAuthorizedEncryptionFlow.d.ts.map +1 -0
- package/dist/Flow/EncryptionFlows/PolicyAuthorizedEncryptionFlow.js +220 -0
- package/dist/Flow/EncryptionFlows/index.d.ts +3 -0
- package/dist/Flow/EncryptionFlows/index.d.ts.map +1 -0
- package/dist/Flow/EncryptionFlows/index.js +18 -0
- package/dist/Flow/SigningFlows/AuthorizedSigningFlow.d.ts +12 -0
- package/dist/Flow/SigningFlows/AuthorizedSigningFlow.d.ts.map +1 -0
- package/dist/Flow/SigningFlows/AuthorizedSigningFlow.js +50 -0
- package/dist/Flow/SigningFlows/dTestVVkSigningFlow.d.ts +15 -0
- package/dist/Flow/SigningFlows/dTestVVkSigningFlow.d.ts.map +1 -0
- package/dist/Flow/SigningFlows/dTestVVkSigningFlow.js +67 -0
- package/dist/Flow/SigningFlows/dVVKSigningFlow.d.ts +17 -0
- package/dist/Flow/SigningFlows/dVVKSigningFlow.d.ts.map +1 -0
- package/dist/Flow/SigningFlows/dVVKSigningFlow.js +61 -0
- package/dist/Flow/SigningFlows/dVVKSigningFlow2Step.d.ts +28 -0
- package/dist/Flow/SigningFlows/dVVKSigningFlow2Step.d.ts.map +1 -0
- package/dist/Flow/SigningFlows/dVVKSigningFlow2Step.js +118 -0
- package/dist/Flow/SigningFlows/index.d.ts +5 -0
- package/dist/Flow/SigningFlows/index.d.ts.map +1 -0
- package/dist/Flow/SigningFlows/index.js +20 -0
- package/dist/Flow/VoucherFlows/VoucherFlow.d.ts +16 -0
- package/dist/Flow/VoucherFlows/VoucherFlow.d.ts.map +1 -0
- package/dist/Flow/VoucherFlows/VoucherFlow.js +34 -0
- package/dist/Flow/VoucherFlows/index.d.ts +2 -0
- package/dist/Flow/VoucherFlows/index.d.ts.map +1 -0
- package/dist/Flow/VoucherFlows/index.js +17 -0
- package/dist/Flow/index.d.ts +5 -0
- package/dist/Flow/index.d.ts.map +1 -0
- package/dist/Flow/index.js +20 -0
- package/dist/Math/KeyDecryption.d.ts +3 -0
- package/dist/Math/KeyDecryption.d.ts.map +1 -0
- package/dist/Math/KeyDecryption.js +24 -0
- package/dist/Math/KeySigning.d.ts +4 -0
- package/dist/Math/KeySigning.d.ts.map +1 -0
- package/dist/Math/KeySigning.js +28 -0
- package/dist/Math/index.d.ts +3 -0
- package/dist/Math/index.d.ts.map +1 -0
- package/dist/Math/index.js +18 -0
- package/dist/Models/AuthRequest.d.ts +13 -0
- package/dist/Models/AuthRequest.d.ts.map +1 -0
- package/dist/Models/AuthRequest.js +46 -0
- package/dist/Models/BaseTideRequest.d.ts +55 -0
- package/dist/Models/BaseTideRequest.d.ts.map +1 -0
- package/dist/Models/BaseTideRequest.js +299 -0
- package/dist/Models/CustomTideRequest.d.ts +19 -0
- package/dist/Models/CustomTideRequest.d.ts.map +1 -0
- package/dist/Models/CustomTideRequest.js +30 -0
- package/dist/Models/Datum.d.ts +11 -0
- package/dist/Models/Datum.d.ts.map +1 -0
- package/dist/Models/Datum.js +33 -0
- package/dist/Models/Doken.d.ts +33 -0
- package/dist/Models/Doken.d.ts.map +1 -0
- package/dist/Models/Doken.js +133 -0
- package/dist/Models/EnclaveEntry.d.ts +14 -0
- package/dist/Models/EnclaveEntry.d.ts.map +1 -0
- package/dist/Models/EnclaveEntry.js +49 -0
- package/dist/Models/Infos/KeyInfo.d.ts +24 -0
- package/dist/Models/Infos/KeyInfo.d.ts.map +1 -0
- package/dist/Models/Infos/KeyInfo.js +51 -0
- package/dist/Models/Infos/OrkInfo.d.ts +18 -0
- package/dist/Models/Infos/OrkInfo.d.ts.map +1 -0
- package/dist/Models/Infos/OrkInfo.js +58 -0
- package/dist/Models/Infos/index.d.ts +3 -0
- package/dist/Models/Infos/index.d.ts.map +1 -0
- package/dist/Models/Infos/index.js +18 -0
- package/dist/Models/ModelRegistry.d.ts +29 -0
- package/dist/Models/ModelRegistry.d.ts.map +1 -0
- package/dist/Models/ModelRegistry.js +321 -0
- package/dist/Models/Policy.d.ts +41 -0
- package/dist/Models/Policy.d.ts.map +1 -0
- package/dist/Models/Policy.js +317 -0
- package/dist/Models/PolicyProtectedSerializedField.d.ts +12 -0
- package/dist/Models/PolicyProtectedSerializedField.d.ts.map +1 -0
- package/dist/Models/PolicyProtectedSerializedField.js +50 -0
- package/dist/Models/Responses/Vendor/VoucherResponse.d.ts +12 -0
- package/dist/Models/Responses/Vendor/VoucherResponse.d.ts.map +1 -0
- package/dist/Models/Responses/Vendor/VoucherResponse.js +39 -0
- package/dist/Models/Responses/Vendor/index.d.ts +2 -0
- package/dist/Models/Responses/Vendor/index.d.ts.map +1 -0
- package/dist/Models/Responses/Vendor/index.js +17 -0
- package/dist/Models/Responses/index.d.ts +2 -0
- package/dist/Models/Responses/index.d.ts.map +1 -0
- package/dist/Models/Responses/index.js +17 -0
- package/dist/Models/SerializedField.d.ts +12 -0
- package/dist/Models/SerializedField.d.ts.map +1 -0
- package/dist/Models/SerializedField.js +50 -0
- package/dist/Models/VendorData.d.ts +12 -0
- package/dist/Models/VendorData.d.ts.map +1 -0
- package/dist/Models/VendorData.js +38 -0
- package/dist/Models/VendorSettings.d.ts +9 -0
- package/dist/Models/VendorSettings.d.ts.map +1 -0
- package/dist/Models/VendorSettings.js +32 -0
- package/dist/Models/index.d.ts +13 -0
- package/dist/Models/index.d.ts.map +1 -0
- package/dist/Models/index.js +30 -0
- package/dist/Tools/TideMemory.d.ts +10 -0
- package/dist/Tools/TideMemory.d.ts.map +1 -0
- package/dist/Tools/TideMemory.js +105 -0
- package/dist/Tools/Utils.d.ts +13 -0
- package/dist/Tools/Utils.d.ts.map +1 -0
- package/dist/Tools/Utils.js +242 -0
- package/dist/Tools/index.d.ts +3 -0
- package/dist/Tools/index.d.ts.map +1 -0
- package/dist/Tools/index.js +18 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/package.json +27 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Tide Protocol - Infrastructure for a TRUE Zero-Trust paradigm
|
|
3
|
+
// Copyright (C) 2022 Tide Foundation Ltd
|
|
4
|
+
//
|
|
5
|
+
// This program is free software and is subject to the terms of
|
|
6
|
+
// the Tide Community Open Code License as published by the
|
|
7
|
+
// Tide Foundation Limited. You may modify it and redistribute
|
|
8
|
+
// it in accordance with and subject to the terms of that License.
|
|
9
|
+
// This program is distributed WITHOUT WARRANTY of any kind,
|
|
10
|
+
// including without any implied warranty of MERCHANTABILITY or
|
|
11
|
+
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
// See the Tide Community Open Code License for more details.
|
|
13
|
+
// You should have received a copy of the Tide Community Open
|
|
14
|
+
// Code License along with this program.
|
|
15
|
+
// If not, see https://tide.org/licenses_tcoc2-0-0-en
|
|
16
|
+
//
|
|
17
|
+
import { base64ToBytes, Bytes2Hex, bytesToBase64, ConcatUint8Arrays, getBytesFromInt16, Hex2Bytes } from "../Serialization";
|
|
18
|
+
import { Registery } from "./ComponentRegistry";
|
|
19
|
+
import { SchemeType } from "./Schemes/SchemeRegistry";
|
|
20
|
+
export class BaseComponent {
|
|
21
|
+
constructor() { }
|
|
22
|
+
Add(component) {
|
|
23
|
+
if (component.Scheme == this.Scheme) {
|
|
24
|
+
let res = this.AddComponent(component);
|
|
25
|
+
if (res instanceof BaseComponent && res.Scheme == this.Scheme)
|
|
26
|
+
return res;
|
|
27
|
+
}
|
|
28
|
+
throw Error("Mismatch between components");
|
|
29
|
+
}
|
|
30
|
+
Multiply(component) {
|
|
31
|
+
if (component.Scheme == this.Scheme) {
|
|
32
|
+
let res = this.MultiplyComponent(component);
|
|
33
|
+
if (res instanceof BaseComponent && res.Scheme == this.Scheme)
|
|
34
|
+
return res;
|
|
35
|
+
}
|
|
36
|
+
throw Error("Mismatch between components");
|
|
37
|
+
}
|
|
38
|
+
Minus(component) {
|
|
39
|
+
if (component.Scheme == this.Scheme) {
|
|
40
|
+
let res = this.MinusComponent(component);
|
|
41
|
+
if (res instanceof BaseComponent && res.Scheme == this.Scheme)
|
|
42
|
+
return res;
|
|
43
|
+
}
|
|
44
|
+
throw Error("Mismatch between components");
|
|
45
|
+
}
|
|
46
|
+
Equals(component) {
|
|
47
|
+
if (component.Scheme == this.Scheme) {
|
|
48
|
+
let res = this.EqualsComponent(component);
|
|
49
|
+
if (typeof res == "boolean")
|
|
50
|
+
return res;
|
|
51
|
+
}
|
|
52
|
+
throw Error("Mismatch between components");
|
|
53
|
+
}
|
|
54
|
+
Mod() {
|
|
55
|
+
let res = this.ModComponent();
|
|
56
|
+
if (res instanceof BaseComponent && res.Scheme == this.Scheme)
|
|
57
|
+
return res;
|
|
58
|
+
throw Error("Mismatch between components");
|
|
59
|
+
}
|
|
60
|
+
ModInv() {
|
|
61
|
+
let res = this.ModInvComponent();
|
|
62
|
+
if (res instanceof BaseComponent && res.Scheme == this.Scheme)
|
|
63
|
+
return res;
|
|
64
|
+
throw Error("Mismatch between components");
|
|
65
|
+
}
|
|
66
|
+
AddComponent(component) { throw Error("Add not implemented"); }
|
|
67
|
+
MultiplyComponent(component) { throw Error("Multiply not implemented"); }
|
|
68
|
+
MinusComponent(component) { throw Error("Minus not implemented"); }
|
|
69
|
+
EqualsComponent(component) { throw Error("Equals not implemented"); }
|
|
70
|
+
ModComponent() { throw Error("Mod not implemented"); }
|
|
71
|
+
ModInvComponent() { throw Error("Mod inv not implemented"); }
|
|
72
|
+
SerializeComponent() { throw Error("Serialize not implemented"); }
|
|
73
|
+
/**@returns {BaseScheme} */
|
|
74
|
+
get Scheme() { throw Error("Not implemented"); }
|
|
75
|
+
/**@returns {string} */
|
|
76
|
+
get ComponentType() { throw Error("Not implemented"); }
|
|
77
|
+
Serialize() {
|
|
78
|
+
let raw = this.SerializeComponent();
|
|
79
|
+
let schemeInt = SchemeType.indexOf(this.Scheme);
|
|
80
|
+
let componentTypeInt = ComponentKeyType.indexOf(this.ComponentType);
|
|
81
|
+
if (schemeInt == -1 || componentTypeInt == -1)
|
|
82
|
+
throw Error("Could not find scheme or component type in registries");
|
|
83
|
+
let schemeBytes = getBytesFromInt16(schemeInt);
|
|
84
|
+
let header = ConcatUint8Arrays([new Uint8Array([componentTypeInt << 4]), schemeBytes]); // shift to the left (for when we have version, but all versions are 0 for now)
|
|
85
|
+
return new SerializedComponent(ConcatUint8Arrays([header, raw]), this.ComponentType);
|
|
86
|
+
}
|
|
87
|
+
static DeserializeComponent(serialized) {
|
|
88
|
+
let b = [];
|
|
89
|
+
if (!(serialized instanceof Uint8Array)) {
|
|
90
|
+
try {
|
|
91
|
+
try {
|
|
92
|
+
b = Hex2Bytes(serialized);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
b = base64ToBytes(serialized);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
throw Error("Unable to deserialize component");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else
|
|
103
|
+
b = serialized;
|
|
104
|
+
let scheme = SchemeType[toInt16(b.slice(1, 3), 0)];
|
|
105
|
+
let k = (b[0] >> 4) & 0x0F;
|
|
106
|
+
let keyType = ComponentKeyType[k];
|
|
107
|
+
let component = Registery[scheme.Name][keyType];
|
|
108
|
+
return component.Create(b.slice(3));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
BaseComponent.Name = () => { throw Error("Name not implemented"); };
|
|
112
|
+
BaseComponent.Version = () => { throw Error("Version not implemented"); };
|
|
113
|
+
export class BaseSeedComponent extends BaseComponent {
|
|
114
|
+
get ComponentType() { return Seed; }
|
|
115
|
+
static New() { throw Error("Not implemented"); }
|
|
116
|
+
GetPublic() { throw Error("Not implemented"); }
|
|
117
|
+
GetPrivate() { throw Error("Not implemented"); }
|
|
118
|
+
get rawBytes() { throw Error("Not implemented"); }
|
|
119
|
+
}
|
|
120
|
+
export class BasePrivateComponent extends BaseComponent {
|
|
121
|
+
get ComponentType() { return Private; }
|
|
122
|
+
static New() { throw Error("Not implemented"); }
|
|
123
|
+
GetPublic() { throw Error("Not implemented"); }
|
|
124
|
+
get priv() { throw Error("Not implemented"); }
|
|
125
|
+
get rawBytes() { throw Error("Not implemented"); }
|
|
126
|
+
}
|
|
127
|
+
export class BasePublicComponent extends BaseComponent {
|
|
128
|
+
get ComponentType() { return Public; }
|
|
129
|
+
get public() { throw Error("Not implemented"); }
|
|
130
|
+
}
|
|
131
|
+
export class SerializedComponent {
|
|
132
|
+
constructor(bytes, compentType) {
|
|
133
|
+
this.Bytes = bytes;
|
|
134
|
+
this.ComponentType = compentType;
|
|
135
|
+
}
|
|
136
|
+
ToBytes() {
|
|
137
|
+
return this.Bytes;
|
|
138
|
+
}
|
|
139
|
+
ToString() {
|
|
140
|
+
switch (this.ComponentType) {
|
|
141
|
+
case Seed:
|
|
142
|
+
return bytesToBase64(this.Bytes);
|
|
143
|
+
case Private:
|
|
144
|
+
return bytesToBase64(this.Bytes);
|
|
145
|
+
case Public:
|
|
146
|
+
return Bytes2Hex(this.Bytes);
|
|
147
|
+
case Symmetric:
|
|
148
|
+
return bytesToBase64(this.Bytes);
|
|
149
|
+
case QuantumPrivate:
|
|
150
|
+
throw Error("Not implemented yet");
|
|
151
|
+
case QuantumPublic:
|
|
152
|
+
throw Error("Not implemented yet");
|
|
153
|
+
default:
|
|
154
|
+
throw Error("Unknown component type");
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function toInt16(bytes, offset = 0) {
|
|
159
|
+
const buffer = bytes.buffer;
|
|
160
|
+
const view = new DataView(buffer);
|
|
161
|
+
return view.getInt16(offset, true); // 'true' for little-endian, set to 'false' for big-endian
|
|
162
|
+
}
|
|
163
|
+
export const Seed = "Seed";
|
|
164
|
+
export const Private = "Private";
|
|
165
|
+
export const Public = "Public";
|
|
166
|
+
export const Symmetric = "Symmetric";
|
|
167
|
+
export const QuantumPrivate = "QuantumPrivate";
|
|
168
|
+
export const QuantumPublic = "QuantumPublic";
|
|
169
|
+
const ComponentKeyType = [
|
|
170
|
+
Seed, // 0
|
|
171
|
+
Private, // 1
|
|
172
|
+
Public, // 2
|
|
173
|
+
Symmetric, // 3
|
|
174
|
+
QuantumPrivate, // 4
|
|
175
|
+
QuantumPublic // 5
|
|
176
|
+
];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Ed25519PrivateComponent, Ed25519PublicComponent, Ed25519SeedComponent } from "./Schemes/Ed25519/Ed25519Components";
|
|
2
|
+
export declare class Ed25519PublicComponentFactory {
|
|
3
|
+
static Create(b: any): Ed25519PublicComponent;
|
|
4
|
+
}
|
|
5
|
+
export declare class Ed25519PrivateComponentFactory {
|
|
6
|
+
static Create(b: any): Ed25519PrivateComponent;
|
|
7
|
+
}
|
|
8
|
+
export declare class Ed25519SeedComponentFactory {
|
|
9
|
+
static Create(b: any): Ed25519SeedComponent;
|
|
10
|
+
}
|
|
11
|
+
export declare const Registery: {
|
|
12
|
+
Ed25519Scheme: {
|
|
13
|
+
Public: typeof Ed25519PublicComponentFactory;
|
|
14
|
+
Private: typeof Ed25519PrivateComponentFactory;
|
|
15
|
+
Seed: typeof Ed25519SeedComponentFactory;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=ComponentRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComponentRegistry.d.ts","sourceRoot":"","sources":["../../../Cryptide/Components/ComponentRegistry.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAG,uBAAuB,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAE7H,qBAAa,6BAA6B;IACtC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAA;CAGlB;AAED,qBAAa,8BAA8B;IACvC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAA;CAGlB;AAED,qBAAa,2BAA2B;IACpC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAA;CAGlB;AAED,eAAO,MAAM,SAAS;;;;;;CAMrB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Tide Protocol - Infrastructure for a TRUE Zero-Trust paradigm
|
|
3
|
+
// Copyright (C) 2022 Tide Foundation Ltd
|
|
4
|
+
//
|
|
5
|
+
// This program is free software and is subject to the terms of
|
|
6
|
+
// the Tide Community Open Code License as published by the
|
|
7
|
+
// Tide Foundation Limited. You may modify it and redistribute
|
|
8
|
+
// it in accordance with and subject to the terms of that License.
|
|
9
|
+
// This program is distributed WITHOUT WARRANTY of any kind,
|
|
10
|
+
// including without any implied warranty of MERCHANTABILITY or
|
|
11
|
+
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
// See the Tide Community Open Code License for more details.
|
|
13
|
+
// You should have received a copy of the Tide Community Open
|
|
14
|
+
// Code License along with this program.
|
|
15
|
+
// If not, see https://tide.org/licenses_tcoc2-0-0-en
|
|
16
|
+
//
|
|
17
|
+
import { Ed25519PrivateComponent, Ed25519PublicComponent, Ed25519SeedComponent } from "./Schemes/Ed25519/Ed25519Components";
|
|
18
|
+
export class Ed25519PublicComponentFactory {
|
|
19
|
+
static Create(b) {
|
|
20
|
+
return new Ed25519PublicComponent(b);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class Ed25519PrivateComponentFactory {
|
|
24
|
+
static Create(b) {
|
|
25
|
+
return new Ed25519PrivateComponent(b);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export class Ed25519SeedComponentFactory {
|
|
29
|
+
static Create(b) {
|
|
30
|
+
return new Ed25519SeedComponent(b);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export const Registery = {
|
|
34
|
+
Ed25519Scheme: {
|
|
35
|
+
Public: Ed25519PublicComponentFactory,
|
|
36
|
+
Private: Ed25519PrivateComponentFactory,
|
|
37
|
+
Seed: Ed25519SeedComponentFactory
|
|
38
|
+
}
|
|
39
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AESScheme.d.ts","sourceRoot":"","sources":["../../../../../Cryptide/Components/Schemes/AES/AESScheme.ts"],"names":[],"mappings":"AAiBA,OAAO,UAAU,MAAM,eAAe,CAAC;AAEvC,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,UAAU;IAC7C,MAAM,KAAK,IAAI,WAA2B;CAC7C"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Tide Protocol - Infrastructure for a TRUE Zero-Trust paradigm
|
|
3
|
+
// Copyright (C) 2022 Tide Foundation Ltd
|
|
4
|
+
//
|
|
5
|
+
// This program is free software and is subject to the terms of
|
|
6
|
+
// the Tide Community Open Code License as published by the
|
|
7
|
+
// Tide Foundation Limited. You may modify it and redistribute
|
|
8
|
+
// it in accordance with and subject to the terms of that License.
|
|
9
|
+
// This program is distributed WITHOUT WARRANTY of any kind,
|
|
10
|
+
// including without any implied warranty of MERCHANTABILITY or
|
|
11
|
+
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
// See the Tide Community Open Code License for more details.
|
|
13
|
+
// You should have received a copy of the Tide Community Open
|
|
14
|
+
// Code License along with this program.
|
|
15
|
+
// If not, see https://tide.org/licenses_tcoc2-0-0-en
|
|
16
|
+
//
|
|
17
|
+
import BaseScheme from "../BaseScheme";
|
|
18
|
+
export default class AESScheme extends BaseScheme {
|
|
19
|
+
static get Name() { return "AESScheme"; }
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../Cryptide/Components/Schemes/AES/index.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Tide Protocol - Infrastructure for a TRUE Zero-Trust paradigm
|
|
3
|
+
// Copyright (C) 2022 Tide Foundation Ltd
|
|
4
|
+
//
|
|
5
|
+
// This program is free software and is subject to the terms of
|
|
6
|
+
// the Tide Community Open Code License as published by the
|
|
7
|
+
// Tide Foundation Limited. You may modify it and redistribute
|
|
8
|
+
// it in accordance with and subject to the terms of that License.
|
|
9
|
+
// This program is distributed WITHOUT WARRANTY of any kind,
|
|
10
|
+
// including without any implied warranty of MERCHANTABILITY or
|
|
11
|
+
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
// See the Tide Community Open Code License for more details.
|
|
13
|
+
// You should have received a copy of the Tide Community Open
|
|
14
|
+
// Code License along with this program.
|
|
15
|
+
// If not, see https://tide.org/licenses_tcoc2-0-0-en
|
|
16
|
+
//
|
|
17
|
+
export { default as AESScheme } from './AESScheme';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseScheme.d.ts","sourceRoot":"","sources":["../../../../Cryptide/Components/Schemes/BaseScheme.ts"],"names":[],"mappings":"AAiBA,MAAM,CAAC,OAAO,OAAO,UAAU;IAC3B,MAAM,KAAK,IAAI,IAAI,MAAM,CAAyC;IAClE,MAAM,CAAC,oBAAoB,QAAO,GAAG,CAA0D;IAC/F,MAAM,CAAC,kBAAkB,QAAO,GAAG,CAAwD;IAC3F,MAAM,CAAC,qBAAqB,QAAO,GAAG,CAA2D;CACpG"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Tide Protocol - Infrastructure for a TRUE Zero-Trust paradigm
|
|
3
|
+
// Copyright (C) 2022 Tide Foundation Ltd
|
|
4
|
+
//
|
|
5
|
+
// This program is free software and is subject to the terms of
|
|
6
|
+
// the Tide Community Open Code License as published by the
|
|
7
|
+
// Tide Foundation Limited. You may modify it and redistribute
|
|
8
|
+
// it in accordance with and subject to the terms of that License.
|
|
9
|
+
// This program is distributed WITHOUT WARRANTY of any kind,
|
|
10
|
+
// including without any implied warranty of MERCHANTABILITY or
|
|
11
|
+
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
// See the Tide Community Open Code License for more details.
|
|
13
|
+
// You should have received a copy of the Tide Community Open
|
|
14
|
+
// Code License along with this program.
|
|
15
|
+
// If not, see https://tide.org/licenses_tcoc2-0-0-en
|
|
16
|
+
//
|
|
17
|
+
class BaseScheme {
|
|
18
|
+
static get Name() { throw Error("Name not implemented"); }
|
|
19
|
+
}
|
|
20
|
+
BaseScheme.GetVerifyingFunction = () => { throw Error("Verifying function not implemented"); };
|
|
21
|
+
BaseScheme.GetSigningFunction = () => { throw Error("Signing function not implemented"); };
|
|
22
|
+
BaseScheme.GetEncryptingFunction = () => { throw Error("Encrypting function not implemented"); };
|
|
23
|
+
export default BaseScheme;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { BaseSeedComponent, BasePrivateComponent, BasePublicComponent } from "../../BaseComponent";
|
|
2
|
+
import Ed25519Scheme from "./Ed25519Scheme";
|
|
3
|
+
export declare class Ed25519PublicComponent extends BasePublicComponent {
|
|
4
|
+
static Name: string;
|
|
5
|
+
static Version: string;
|
|
6
|
+
get Scheme(): typeof Ed25519Scheme;
|
|
7
|
+
get ComponentType(): string;
|
|
8
|
+
/**@type {Uint8Array} */
|
|
9
|
+
pb: any;
|
|
10
|
+
/**@type {Point} */
|
|
11
|
+
p: any;
|
|
12
|
+
constructor(rawData: any);
|
|
13
|
+
get public(): any;
|
|
14
|
+
get rawBytes(): any;
|
|
15
|
+
AddComponent(component: any): Ed25519PublicComponent;
|
|
16
|
+
MultiplyComponent(component: any): Ed25519PublicComponent;
|
|
17
|
+
MinusComponent(component: any): Ed25519PublicComponent;
|
|
18
|
+
EqualsComponent(component: any): any;
|
|
19
|
+
SerializeComponent(): any;
|
|
20
|
+
}
|
|
21
|
+
export declare class Ed25519PrivateComponent extends BasePrivateComponent {
|
|
22
|
+
static Name: string;
|
|
23
|
+
static Version: string;
|
|
24
|
+
get Scheme(): typeof Ed25519Scheme;
|
|
25
|
+
get ComponentType(): string;
|
|
26
|
+
/**@type {bigint} */
|
|
27
|
+
p: any;
|
|
28
|
+
/**@type {Uint8Array} */
|
|
29
|
+
rB: any;
|
|
30
|
+
get priv(): any;
|
|
31
|
+
get rawBytes(): any;
|
|
32
|
+
constructor(rawData: any);
|
|
33
|
+
SerializeComponent(): any;
|
|
34
|
+
GetPublic(): Ed25519PublicComponent;
|
|
35
|
+
static New(): Ed25519PrivateComponent;
|
|
36
|
+
}
|
|
37
|
+
export declare class Ed25519SeedComponent extends BaseSeedComponent {
|
|
38
|
+
static Name: string;
|
|
39
|
+
static Version: string;
|
|
40
|
+
get Scheme(): typeof Ed25519Scheme;
|
|
41
|
+
get ComponentType(): string;
|
|
42
|
+
/**@type {Uint8Array} */
|
|
43
|
+
rB: any;
|
|
44
|
+
get rawBytes(): any;
|
|
45
|
+
constructor(rawData: any);
|
|
46
|
+
SerializeComponent(): any;
|
|
47
|
+
static GenerateSeed(): Uint8Array<any>;
|
|
48
|
+
GetPrivate(): Ed25519PrivateComponent;
|
|
49
|
+
GetPublic(): Ed25519PublicComponent;
|
|
50
|
+
static New(): Ed25519SeedComponent;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=Ed25519Components.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Ed25519Components.d.ts","sourceRoot":"","sources":["../../../../../Cryptide/Components/Schemes/Ed25519/Ed25519Components.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAyB,iBAAiB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1H,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C,qBAAa,sBAAuB,SAAQ,mBAAmB;IAC3D,MAAM,CAAC,IAAI,SAA4B;IACvC,MAAM,CAAC,OAAO,SAAO;IACrB,IAAI,MAAM,yBAA4B;IACtC,IAAI,aAAa,WAAoB;IAErC,wBAAwB;IACxB,EAAE,MAAa;IACf,mBAAmB;IACnB,CAAC,MAAa;gBACF,OAAO,KAAA;IAQnB,IAAI,MAAM,QAIT;IAED,IAAI,QAAQ,QAIX;IAED,YAAY,CAAC,SAAS,KAAA;IAMtB,iBAAiB,CAAC,SAAS,KAAA;IAM3B,cAAc,CAAC,SAAS,KAAA;IAMxB,eAAe,CAAC,SAAS,KAAA;IAMzB,kBAAkB;CAGrB;AAED,qBAAa,uBAAwB,SAAQ,oBAAoB;IAC7D,MAAM,CAAC,IAAI,SAA6B;IACxC,MAAM,CAAC,OAAO,SAAO;IACrB,IAAI,MAAM,yBAA4B;IACtC,IAAI,aAAa,WAAqB;IAEtC,oBAAoB;IACpB,CAAC,MAAa;IACd,wBAAwB;IACxB,EAAE,MAAa;IAEf,IAAI,IAAI,QAIP;IAED,IAAI,QAAQ,QAIX;gBAEW,OAAO,KAAA;IAQnB,kBAAkB;IAGlB,SAAS;IAGT,MAAM,CAAC,GAAG;CAGb;AAED,qBAAa,oBAAqB,SAAQ,iBAAiB;IACvD,MAAM,CAAC,IAAI,SAA0B;IACrC,MAAM,CAAC,OAAO,SAAO;IACrB,IAAI,MAAM,yBAA4B;IACtC,IAAI,aAAa,WAAkB;IAEnC,wBAAwB;IACxB,EAAE,MAAa;IAEf,IAAI,QAAQ,QAEX;gBAEW,OAAO,KAAA;IAOnB,kBAAkB;IAIlB,MAAM,CAAC,YAAY;IAQnB,UAAU;IAIV,SAAS;IAGT,MAAM,CAAC,GAAG;CAGb"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Tide Protocol - Infrastructure for a TRUE Zero-Trust paradigm
|
|
3
|
+
// Copyright (C) 2022 Tide Foundation Ltd
|
|
4
|
+
//
|
|
5
|
+
// This program is free software and is subject to the terms of
|
|
6
|
+
// the Tide Community Open Code License as published by the
|
|
7
|
+
// Tide Foundation Limited. You may modify it and redistribute
|
|
8
|
+
// it in accordance with and subject to the terms of that License.
|
|
9
|
+
// This program is distributed WITHOUT WARRANTY of any kind,
|
|
10
|
+
// including without any implied warranty of MERCHANTABILITY or
|
|
11
|
+
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
// See the Tide Community Open Code License for more details.
|
|
13
|
+
// You should have received a copy of the Tide Community Open
|
|
14
|
+
// Code License along with this program.
|
|
15
|
+
// If not, see https://tide.org/licenses_tcoc2-0-0-en
|
|
16
|
+
//
|
|
17
|
+
import { etc, Point } from "../../../Ed25519";
|
|
18
|
+
import { mod, } from "../../../Math";
|
|
19
|
+
import { BigIntFromByteArray, BigIntToByteArray } from "../../../Serialization";
|
|
20
|
+
import { Public, Private, Seed, BaseSeedComponent, BasePrivateComponent, BasePublicComponent } from "../../BaseComponent";
|
|
21
|
+
import Ed25519Scheme from "./Ed25519Scheme";
|
|
22
|
+
export class Ed25519PublicComponent extends BasePublicComponent {
|
|
23
|
+
get Scheme() { return Ed25519Scheme; }
|
|
24
|
+
get ComponentType() { return Public; }
|
|
25
|
+
;
|
|
26
|
+
constructor(rawData) {
|
|
27
|
+
super();
|
|
28
|
+
/**@type {Uint8Array} */
|
|
29
|
+
this.pb = undefined;
|
|
30
|
+
/**@type {Point} */
|
|
31
|
+
this.p = undefined;
|
|
32
|
+
if (rawData instanceof Point) {
|
|
33
|
+
this.p = rawData;
|
|
34
|
+
}
|
|
35
|
+
else if (rawData instanceof Uint8Array) {
|
|
36
|
+
this.pb = rawData;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
throw Error("unexpected type;");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
get public() {
|
|
43
|
+
if (!this.p && this.pb)
|
|
44
|
+
this.p = Point.fromBytes(this.pb);
|
|
45
|
+
else if (!this.p && !this.pb)
|
|
46
|
+
throw Error("empty object");
|
|
47
|
+
return this.p;
|
|
48
|
+
}
|
|
49
|
+
get rawBytes() {
|
|
50
|
+
if (!this.pb && this.p)
|
|
51
|
+
this.pb = this.p.toRawBytes();
|
|
52
|
+
else if (!this.pb && !this.p)
|
|
53
|
+
throw Error("empty object");
|
|
54
|
+
return this.pb;
|
|
55
|
+
}
|
|
56
|
+
AddComponent(component) {
|
|
57
|
+
if (component instanceof Ed25519PublicComponent) {
|
|
58
|
+
return new Ed25519PublicComponent(this.public.add(component.public));
|
|
59
|
+
}
|
|
60
|
+
throw Error("Mismatch with components");
|
|
61
|
+
}
|
|
62
|
+
MultiplyComponent(component) {
|
|
63
|
+
if (component instanceof Ed25519PrivateComponent) {
|
|
64
|
+
return new Ed25519PublicComponent(this.public.mul(component.priv));
|
|
65
|
+
}
|
|
66
|
+
throw Error("Mismatch with components");
|
|
67
|
+
}
|
|
68
|
+
MinusComponent(component) {
|
|
69
|
+
if (component instanceof Ed25519PublicComponent) {
|
|
70
|
+
return new Ed25519PublicComponent(this.public.add(component.public.negate()));
|
|
71
|
+
}
|
|
72
|
+
throw Error("Mismatch with components");
|
|
73
|
+
}
|
|
74
|
+
EqualsComponent(component) {
|
|
75
|
+
if (component instanceof Ed25519PublicComponent) {
|
|
76
|
+
return this.public.equals(component.public);
|
|
77
|
+
}
|
|
78
|
+
throw Error("Mismatch with components");
|
|
79
|
+
}
|
|
80
|
+
SerializeComponent() {
|
|
81
|
+
return this.rawBytes.slice();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
Ed25519PublicComponent.Name = "Ed25519PublicComponent";
|
|
85
|
+
Ed25519PublicComponent.Version = "1";
|
|
86
|
+
export class Ed25519PrivateComponent extends BasePrivateComponent {
|
|
87
|
+
get Scheme() { return Ed25519Scheme; }
|
|
88
|
+
get ComponentType() { return Private; }
|
|
89
|
+
;
|
|
90
|
+
get priv() {
|
|
91
|
+
if (!this.p && this.rB)
|
|
92
|
+
this.p = BigIntFromByteArray(this.rB);
|
|
93
|
+
else if (!this.p && !this.rB)
|
|
94
|
+
throw Error("Empty object");
|
|
95
|
+
return this.p;
|
|
96
|
+
}
|
|
97
|
+
get rawBytes() {
|
|
98
|
+
if (!this.rB && this.p)
|
|
99
|
+
this.rB = BigIntToByteArray(this.p);
|
|
100
|
+
else if (!this.rB && !this.p)
|
|
101
|
+
throw Error("Empty object");
|
|
102
|
+
return this.rB;
|
|
103
|
+
}
|
|
104
|
+
constructor(rawData) {
|
|
105
|
+
super();
|
|
106
|
+
/**@type {bigint} */
|
|
107
|
+
this.p = undefined;
|
|
108
|
+
/**@type {Uint8Array} */
|
|
109
|
+
this.rB = undefined;
|
|
110
|
+
if (typeof rawData == "bigint") {
|
|
111
|
+
this.p = rawData;
|
|
112
|
+
}
|
|
113
|
+
else if (rawData instanceof Uint8Array) {
|
|
114
|
+
this.rB = rawData;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
throw Error("unexpected type;");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
SerializeComponent() {
|
|
121
|
+
return this.rawBytes.slice();
|
|
122
|
+
}
|
|
123
|
+
GetPublic() {
|
|
124
|
+
return new Ed25519PublicComponent(Point.BASE.mul(this.priv));
|
|
125
|
+
}
|
|
126
|
+
static New() {
|
|
127
|
+
return Ed25519SeedComponent.New().GetPrivate();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
Ed25519PrivateComponent.Name = "Ed25519PrivateComponent";
|
|
131
|
+
Ed25519PrivateComponent.Version = "1";
|
|
132
|
+
export class Ed25519SeedComponent extends BaseSeedComponent {
|
|
133
|
+
get Scheme() { return Ed25519Scheme; }
|
|
134
|
+
get ComponentType() { return Seed; }
|
|
135
|
+
;
|
|
136
|
+
get rawBytes() {
|
|
137
|
+
return this.rB;
|
|
138
|
+
}
|
|
139
|
+
constructor(rawData) {
|
|
140
|
+
super();
|
|
141
|
+
/**@type {Uint8Array} */
|
|
142
|
+
this.rB = undefined;
|
|
143
|
+
if (rawData instanceof Uint8Array)
|
|
144
|
+
this.rB = rawData.slice();
|
|
145
|
+
else if (!rawData)
|
|
146
|
+
this.rB = Ed25519SeedComponent.GenerateSeed(); // if nothing provided - self instanciate
|
|
147
|
+
else
|
|
148
|
+
throw Error("Expecting Uint8Array or nothing for constructor");
|
|
149
|
+
}
|
|
150
|
+
SerializeComponent() {
|
|
151
|
+
return this.rB.slice();
|
|
152
|
+
}
|
|
153
|
+
static GenerateSeed() {
|
|
154
|
+
const head = etc.randomBytes(32);
|
|
155
|
+
head[0] &= 248; // Clamp bits: 0b1111_1000,
|
|
156
|
+
head[31] &= 127; // 0b0111_1111,
|
|
157
|
+
head[31] |= 64; // 0b0100_0000
|
|
158
|
+
return head;
|
|
159
|
+
}
|
|
160
|
+
GetPrivate() {
|
|
161
|
+
return new Ed25519PrivateComponent(mod(BigIntFromByteArray(this.rawBytes)));
|
|
162
|
+
}
|
|
163
|
+
GetPublic() {
|
|
164
|
+
return this.GetPrivate().GetPublic();
|
|
165
|
+
}
|
|
166
|
+
static New() {
|
|
167
|
+
return new Ed25519SeedComponent(this.GenerateSeed());
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
Ed25519SeedComponent.Name = "Ed25519SeedComponent";
|
|
171
|
+
Ed25519SeedComponent.Version = "1";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import BaseScheme from "../BaseScheme";
|
|
2
|
+
export default class Ed25519Scheme extends BaseScheme {
|
|
3
|
+
static get Name(): string;
|
|
4
|
+
/**
|
|
5
|
+
* WITHOUT DETERMINISM. Prefix is generated via randomisation.
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
static GetSigningFunction: () => (msg: any, component: any) => Promise<any>;
|
|
9
|
+
static GetVerifyingFunction: () => (msg: any, signature: any, component: any) => Promise<void>;
|
|
10
|
+
static GetEncryptingFunction: () => (msg: any, component: any) => Promise<Uint8Array<ArrayBuffer>>;
|
|
11
|
+
static GetDecryptingFunction: () => (cipher: any, component: any) => Promise<Uint8Array<ArrayBuffer>>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=Ed25519Scheme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Ed25519Scheme.d.ts","sourceRoot":"","sources":["../../../../../Cryptide/Components/Schemes/Ed25519/Ed25519Scheme.ts"],"names":[],"mappings":"AAmBA,OAAO,UAAU,MAAM,eAAe,CAAC;AAGvC,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,UAAU;IACjD,MAAM,KAAK,IAAI,WAA8B;IAC7C;;;OAGG;IACH,MAAM,CAAC,kBAAkB,mDAQxB;IACD,MAAM,CAAC,oBAAoB,oEAS1B;IACD,MAAM,CAAC,qBAAqB,uEAQ3B;IACD,MAAM,CAAC,qBAAqB,0EAQ3B;CACJ"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Tide Protocol - Infrastructure for a TRUE Zero-Trust paradigm
|
|
3
|
+
// Copyright (C) 2022 Tide Foundation Ltd
|
|
4
|
+
//
|
|
5
|
+
// This program is free software and is subject to the terms of
|
|
6
|
+
// the Tide Community Open Code License as published by the
|
|
7
|
+
// Tide Foundation Limited. You may modify it and redistribute
|
|
8
|
+
// it in accordance with and subject to the terms of that License.
|
|
9
|
+
// This program is distributed WITHOUT WARRANTY of any kind,
|
|
10
|
+
// including without any implied warranty of MERCHANTABILITY or
|
|
11
|
+
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
// See the Tide Community Open Code License for more details.
|
|
13
|
+
// You should have received a copy of the Tide Community Open
|
|
14
|
+
// Code License along with this program.
|
|
15
|
+
// If not, see https://tide.org/licenses_tcoc2-0-0-en
|
|
16
|
+
//
|
|
17
|
+
var _a;
|
|
18
|
+
import { signNonDeterministicAsync, verifyAsync } from "../../../Ed25519";
|
|
19
|
+
import ElGamal from "../../../Encryption/ElGamal";
|
|
20
|
+
import BaseScheme from "../BaseScheme";
|
|
21
|
+
import { Ed25519PrivateComponent, Ed25519PublicComponent } from "./Ed25519Components";
|
|
22
|
+
class Ed25519Scheme extends BaseScheme {
|
|
23
|
+
static get Name() { return "Ed25519Scheme"; }
|
|
24
|
+
}
|
|
25
|
+
_a = Ed25519Scheme;
|
|
26
|
+
/**
|
|
27
|
+
* WITHOUT DETERMINISM. Prefix is generated via randomisation.
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
Ed25519Scheme.GetSigningFunction = () => {
|
|
31
|
+
const signingFunc = (msg, component) => {
|
|
32
|
+
if (msg instanceof Uint8Array && component instanceof Ed25519PrivateComponent) {
|
|
33
|
+
return signNonDeterministicAsync(msg, component.priv);
|
|
34
|
+
}
|
|
35
|
+
throw Error("Mismatch of expected types (Uint8Array, Ed25519PrivateComponent)");
|
|
36
|
+
};
|
|
37
|
+
return signingFunc;
|
|
38
|
+
};
|
|
39
|
+
Ed25519Scheme.GetVerifyingFunction = () => {
|
|
40
|
+
const verifyingFunc = async (msg, signature, component) => {
|
|
41
|
+
if (msg instanceof Uint8Array && signature instanceof Uint8Array && component instanceof Ed25519PublicComponent) {
|
|
42
|
+
const valid = await verifyAsync(signature, msg, component.rawBytes);
|
|
43
|
+
if (!valid)
|
|
44
|
+
throw Error("Signature validation failed");
|
|
45
|
+
}
|
|
46
|
+
else
|
|
47
|
+
throw Error("Mismatch of expected types (Uint8Array, Uint8Array, Ed25519PublicComponent)");
|
|
48
|
+
};
|
|
49
|
+
return verifyingFunc;
|
|
50
|
+
};
|
|
51
|
+
Ed25519Scheme.GetEncryptingFunction = () => {
|
|
52
|
+
const encryptingFunc = async (msg, component) => {
|
|
53
|
+
if (msg instanceof Uint8Array && component instanceof Ed25519PublicComponent) {
|
|
54
|
+
return await ElGamal.encryptDataRaw(msg, component.public);
|
|
55
|
+
}
|
|
56
|
+
else
|
|
57
|
+
throw Error("Mismatch between expected types (Uint8Array, Ed25519PublicComponent)");
|
|
58
|
+
};
|
|
59
|
+
return encryptingFunc;
|
|
60
|
+
};
|
|
61
|
+
Ed25519Scheme.GetDecryptingFunction = () => {
|
|
62
|
+
const decryptingFunc = async (cipher, component) => {
|
|
63
|
+
if (cipher instanceof Uint8Array && component instanceof Ed25519PrivateComponent) {
|
|
64
|
+
return await ElGamal.decryptDataRaw(cipher, component.priv);
|
|
65
|
+
}
|
|
66
|
+
else
|
|
67
|
+
throw Error("Mismatch between expected types (Uint8Array, Ed25519PrivateComponent)");
|
|
68
|
+
};
|
|
69
|
+
return decryptingFunc;
|
|
70
|
+
};
|
|
71
|
+
export default Ed25519Scheme;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../Cryptide/Components/Schemes/Ed25519/index.ts"],"names":[],"mappings":"AAiBA,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|