@tideorg/js 0.0.1
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 +59 -0
- package/dist/Cryptide/Signing/TideSignature.d.ts.map +1 -0
- package/dist/Cryptide/Signing/TideSignature.js +118 -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 +14 -0
- package/dist/Models/AuthRequest.d.ts.map +1 -0
- package/dist/Models/AuthRequest.js +48 -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 +244 -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,299 @@
|
|
|
1
|
+
import { Doken as ContractDoken } from "../Contracts/BaseContract";
|
|
2
|
+
import { TideMemory } from "../Tools/TideMemory";
|
|
3
|
+
import { Policy } from "./Policy";
|
|
4
|
+
import { SHA512_Digest } from "../Cryptide/Hashing/Hash";
|
|
5
|
+
import { bytesToBase64, StringToUint8Array } from "../Cryptide/Serialization";
|
|
6
|
+
import { PolicyAuthorizedTideRequestSignatureFormat } from "../Cryptide/Signing/TideSignature";
|
|
7
|
+
import { Serialization } from "../Cryptide";
|
|
8
|
+
export default class BaseTideRequest {
|
|
9
|
+
constructor(name, version, authFlow, draft = new Uint8Array(), dyanmicData = new Uint8Array()) {
|
|
10
|
+
this.name = name;
|
|
11
|
+
this.version = version;
|
|
12
|
+
this.authFlow = authFlow;
|
|
13
|
+
this.draft = new TideMemory(draft.length);
|
|
14
|
+
this.draft.set(draft);
|
|
15
|
+
this.dyanmicData = new TideMemory(dyanmicData.length);
|
|
16
|
+
this.dyanmicData.set(dyanmicData);
|
|
17
|
+
this.authorization = new TideMemory();
|
|
18
|
+
this.authorizerCert = new TideMemory();
|
|
19
|
+
;
|
|
20
|
+
this.authorizer = new TideMemory();
|
|
21
|
+
this.expiry = Math.floor(Date.now() / 1000) + 30; // default is 30s
|
|
22
|
+
this.policy = new TideMemory();
|
|
23
|
+
}
|
|
24
|
+
id() {
|
|
25
|
+
return this.name + ":" + this.version;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* This isn't copying. Just created another BaseTideRequest object that allows you to point each individual field to OTHER sections of memory.
|
|
29
|
+
* If you modify an existing 'replicated' field, you'll also modify the other object you originally replicated.
|
|
30
|
+
*/
|
|
31
|
+
replicate() {
|
|
32
|
+
const r = new BaseTideRequest(this.name, this.version, this.authFlow, this.draft, this.dyanmicData);
|
|
33
|
+
r.authorization = this.authorization;
|
|
34
|
+
r.authorizerCert = this.authorizerCert;
|
|
35
|
+
r.authorizer = this.authorizer;
|
|
36
|
+
r.expiry = this.expiry;
|
|
37
|
+
r.policy = this.policy;
|
|
38
|
+
return r;
|
|
39
|
+
}
|
|
40
|
+
setNewDynamicData(d) {
|
|
41
|
+
this.dyanmicData = new TideMemory(d.length);
|
|
42
|
+
this.dyanmicData.set(d);
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
setCustomExpiry(timeFromNowInSeconds) {
|
|
46
|
+
this.expiry = Math.floor(Date.now() / 1000) + timeFromNowInSeconds;
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
addAuthorizer(authorizer) {
|
|
50
|
+
this.authorizer = new TideMemory(authorizer.length);
|
|
51
|
+
this.authorizer.set(authorizer);
|
|
52
|
+
}
|
|
53
|
+
addAuthorizerCertificate(authorizerCertificate) {
|
|
54
|
+
this.authorizerCert = new TideMemory(authorizerCertificate.length);
|
|
55
|
+
this.authorizerCert.set(authorizerCertificate);
|
|
56
|
+
}
|
|
57
|
+
addAuthorization(authorization) {
|
|
58
|
+
this.authorization = new TideMemory(authorization.length);
|
|
59
|
+
this.authorization.set(authorization);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
addPolicy(policy) {
|
|
63
|
+
this.policy = new TideMemory(policy.length);
|
|
64
|
+
this.policy.set(policy);
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
hasPolicy() {
|
|
68
|
+
return this.policy.length != 0;
|
|
69
|
+
}
|
|
70
|
+
// Additional method from tide-js version
|
|
71
|
+
async dataToAuthorize() {
|
|
72
|
+
return StringToUint8Array("<datatoauthorize-" + this.name + ":" + this.version + bytesToBase64(await SHA512_Digest(this.draft)) + this.expiry.toString() + "-datatoauthorize>");
|
|
73
|
+
}
|
|
74
|
+
// Additional method from tide-js version
|
|
75
|
+
async dataToApprove() {
|
|
76
|
+
const creationTime = this.authorization.GetValue(0).GetValue(0);
|
|
77
|
+
const creationSig = this.authorization.GetValue(0).GetValue(1);
|
|
78
|
+
const creationMessage = new PolicyAuthorizedTideRequestSignatureFormat(creationTime, this.expiry, this.id(), await SHA512_Digest(this.draft));
|
|
79
|
+
return Serialization.ConcatUint8Arrays([creationMessage.format(), creationSig]);
|
|
80
|
+
}
|
|
81
|
+
async getRequestInitDetails() {
|
|
82
|
+
const te = new TextEncoder();
|
|
83
|
+
return {
|
|
84
|
+
"creationTime": BaseTideRequest.uint32ToUint8ArrayLE(Math.floor(Date.now() / 1000)), // now
|
|
85
|
+
"expireTime": BaseTideRequest.uint32ToUint8ArrayLE(this.expiry),
|
|
86
|
+
"modelId": te.encode(this.id()),
|
|
87
|
+
"draftHash": new TideMemory(await crypto.subtle.digest("SHA-512", this.draft))
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
addCreationSignature(creationTime, sig) {
|
|
91
|
+
this.authorization = TideMemory.CreateFromArray([
|
|
92
|
+
TideMemory.CreateFromArray([
|
|
93
|
+
creationTime,
|
|
94
|
+
sig
|
|
95
|
+
]),
|
|
96
|
+
new TideMemory() // empty as no approvals have been added yet
|
|
97
|
+
]);
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
isInitialized() {
|
|
101
|
+
try {
|
|
102
|
+
// check that creation time and sig fields are present
|
|
103
|
+
if (this.authorization.GetValue(0).GetValue(0).length > 0 && this.authorization.GetValue(0).GetValue(1).length == 64)
|
|
104
|
+
return true;
|
|
105
|
+
else
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
getUniqueId() {
|
|
113
|
+
if (!this.isInitialized())
|
|
114
|
+
throw 'Must initialize request to generate unique id';
|
|
115
|
+
const bytes = this.authorization.GetValue(0).GetValue(1);
|
|
116
|
+
return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join(''); // hex
|
|
117
|
+
}
|
|
118
|
+
getInitializedTime() {
|
|
119
|
+
if (!this.isInitialized())
|
|
120
|
+
throw 'Must initialize request to get creation time';
|
|
121
|
+
const time_bytes = this.authorization.GetValue(0).GetValue(0);
|
|
122
|
+
return BaseTideRequest.uint8ArrayToUint32LE(time_bytes);
|
|
123
|
+
}
|
|
124
|
+
getCurrentApprovalCount() {
|
|
125
|
+
if (!this.isInitialized())
|
|
126
|
+
throw 'Must initialize request to get approval count';
|
|
127
|
+
let i = 0;
|
|
128
|
+
let res = { result: undefined };
|
|
129
|
+
while (this.authorizer.TryGetValue(i, res)) {
|
|
130
|
+
i++;
|
|
131
|
+
}
|
|
132
|
+
return i;
|
|
133
|
+
}
|
|
134
|
+
getPolicy() {
|
|
135
|
+
return Policy.from(this.policy);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Add an approval for this request. To be used for policy auth flow
|
|
139
|
+
*/
|
|
140
|
+
addApproval(doken, sig) {
|
|
141
|
+
// Ensure creation authorization has been added
|
|
142
|
+
let res = {};
|
|
143
|
+
if (!Serialization.TryGetValue(this.authorization, 0, res))
|
|
144
|
+
throw Error("Creation authorization hasn't been added yet");
|
|
145
|
+
// Deconstruct existing authorization
|
|
146
|
+
let existingSessKeySigs = [];
|
|
147
|
+
let currentSig = { result: undefined };
|
|
148
|
+
for (let i = 0; Serialization.TryGetValue(Serialization.GetValue(this.authorization, 1), i, currentSig); i++) {
|
|
149
|
+
if (currentSig.result.length == 0)
|
|
150
|
+
continue;
|
|
151
|
+
existingSessKeySigs.push(currentSig.result);
|
|
152
|
+
}
|
|
153
|
+
// Now deconstruct exsiting authorizers (dokens)
|
|
154
|
+
let existingDokens = [];
|
|
155
|
+
let currentDoken = { result: undefined };
|
|
156
|
+
for (let i = 0; Serialization.TryGetValue(this.authorizer, i, currentDoken); i++) {
|
|
157
|
+
if (currentDoken.result.length == 0)
|
|
158
|
+
continue;
|
|
159
|
+
existingDokens.push(currentDoken.result);
|
|
160
|
+
}
|
|
161
|
+
// Now add the new doken and sig to the deconstructed data then reserialize it into the request
|
|
162
|
+
existingDokens.push(StringToUint8Array(doken.serialize()));
|
|
163
|
+
existingSessKeySigs.push(sig);
|
|
164
|
+
this.authorization = TideMemory.CreateFromArray([
|
|
165
|
+
Serialization.GetValue(this.authorization, 0),
|
|
166
|
+
Serialization.CreateTideMemoryFromArray(existingSessKeySigs)
|
|
167
|
+
]);
|
|
168
|
+
this.authorizer = TideMemory.CreateFromArray(existingDokens);
|
|
169
|
+
}
|
|
170
|
+
removeApproval(approvalVuid) {
|
|
171
|
+
// find if there are any dokens with this approvalVuid
|
|
172
|
+
if (!this.isInitialized())
|
|
173
|
+
return false;
|
|
174
|
+
if (this.getCurrentApprovalCount() == 0)
|
|
175
|
+
return false;
|
|
176
|
+
try {
|
|
177
|
+
// find doken and it's index
|
|
178
|
+
let i = 0;
|
|
179
|
+
let res = { result: new TideMemory() };
|
|
180
|
+
let dokenWithVuidFound = {};
|
|
181
|
+
let keepTheseDokensList = [];
|
|
182
|
+
let keepTheseApprovalSigs = [];
|
|
183
|
+
while (this.authorizer.TryGetValue(i, res)) {
|
|
184
|
+
const d = new ContractDoken(res.result);
|
|
185
|
+
if (d.hasVuid(approvalVuid)) {
|
|
186
|
+
dokenWithVuidFound = {
|
|
187
|
+
index: i,
|
|
188
|
+
value: d
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
keepTheseDokensList.push(res.result);
|
|
193
|
+
keepTheseApprovalSigs.push(this.authorization.GetValue(1).GetValue(i));
|
|
194
|
+
}
|
|
195
|
+
i++;
|
|
196
|
+
}
|
|
197
|
+
// reconstruct authorizers and authorizer sigs of request
|
|
198
|
+
if (dokenWithVuidFound) {
|
|
199
|
+
const creationAuth = this.authorization.GetValue(0);
|
|
200
|
+
this.authorization = TideMemory.CreateFromArray([
|
|
201
|
+
creationAuth,
|
|
202
|
+
TideMemory.CreateFromArray(keepTheseApprovalSigs)
|
|
203
|
+
]);
|
|
204
|
+
this.authorizer = TideMemory.CreateFromArray(keepTheseDokensList);
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
else
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
catch (ex) {
|
|
211
|
+
console.error(ex);
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
encode() {
|
|
216
|
+
if (this.authorizer == null)
|
|
217
|
+
throw Error("Authorizer not added to request");
|
|
218
|
+
if (this.authorizerCert == null)
|
|
219
|
+
throw Error("Authorizer cert not provided");
|
|
220
|
+
if (this.authorization == null)
|
|
221
|
+
throw Error("Authorize this request first with an authorizer");
|
|
222
|
+
const te = new TextEncoder();
|
|
223
|
+
const name_b = te.encode(this.name);
|
|
224
|
+
const version_b = te.encode(this.version);
|
|
225
|
+
const authFlow_b = te.encode(this.authFlow);
|
|
226
|
+
const expiry = BaseTideRequest.uint32ToUint8ArrayLE(this.expiry);
|
|
227
|
+
const req = TideMemory.CreateFromArray([
|
|
228
|
+
name_b,
|
|
229
|
+
version_b,
|
|
230
|
+
expiry,
|
|
231
|
+
this.draft,
|
|
232
|
+
authFlow_b,
|
|
233
|
+
this.dyanmicData,
|
|
234
|
+
this.authorizer,
|
|
235
|
+
this.authorization,
|
|
236
|
+
this.authorizerCert,
|
|
237
|
+
this.policy
|
|
238
|
+
]);
|
|
239
|
+
return req;
|
|
240
|
+
}
|
|
241
|
+
static decode(data) {
|
|
242
|
+
const d = new TideMemory(data.length);
|
|
243
|
+
d.set(data);
|
|
244
|
+
// Read field 0 (name) - this is part of the TideMemory structure
|
|
245
|
+
const name = new TextDecoder().decode(d.GetValue(0));
|
|
246
|
+
// Read all other fields
|
|
247
|
+
const version = new TextDecoder().decode(d.GetValue(1));
|
|
248
|
+
// Check name and version in static members if set
|
|
249
|
+
if (this._name != undefined && this._version != undefined) {
|
|
250
|
+
if (name != this._name || version != this._version)
|
|
251
|
+
throw Error("Name and Version in decoded data don't match this object's set name and version.");
|
|
252
|
+
}
|
|
253
|
+
const expiry = BaseTideRequest.uint8ArrayToUint32LE(d.GetValue(2));
|
|
254
|
+
const draft = d.GetValue(3);
|
|
255
|
+
const authFlow = new TextDecoder().decode(d.GetValue(4));
|
|
256
|
+
const dynamicData = d.GetValue(5);
|
|
257
|
+
const authorizer = d.GetValue(6);
|
|
258
|
+
const authorization = d.GetValue(7);
|
|
259
|
+
const authorizerCert = d.GetValue(8);
|
|
260
|
+
const policy = d.GetValue(9);
|
|
261
|
+
// Create a new instance using 'this' constructor to support subclasses
|
|
262
|
+
const request = new this(name, version, authFlow, draft, dynamicData);
|
|
263
|
+
// Set the remaining fields
|
|
264
|
+
request.expiry = expiry;
|
|
265
|
+
request.authorizer = authorizer;
|
|
266
|
+
request.authorization = authorization;
|
|
267
|
+
request.authorizerCert = authorizerCert;
|
|
268
|
+
request.policy = policy;
|
|
269
|
+
return request;
|
|
270
|
+
}
|
|
271
|
+
static uint32ToUint8ArrayLE(num) {
|
|
272
|
+
// We want 8 bytes to match .NET Int64 (long) layout: low 32 bits in first 4 bytes, rest zero.
|
|
273
|
+
const arr = new Uint8Array(8);
|
|
274
|
+
// low 32 bits, little-endian
|
|
275
|
+
arr[0] = num & 0xff;
|
|
276
|
+
arr[1] = (num >>> 8) & 0xff;
|
|
277
|
+
arr[2] = (num >>> 16) & 0xff;
|
|
278
|
+
arr[3] = (num >>> 24) & 0xff;
|
|
279
|
+
// arr[4..7] are already 0 from Uint8Array init, matching a .NET long with high 32 bits = 0.
|
|
280
|
+
return arr;
|
|
281
|
+
}
|
|
282
|
+
static uint8ArrayToUint32LE(bytes) {
|
|
283
|
+
if (bytes.length !== 8) {
|
|
284
|
+
throw new Error("Expected 8 bytes for a 64-bit value");
|
|
285
|
+
}
|
|
286
|
+
// Optional safety check: ensure high 32 bits are zero (no real 64-bit longs passed).
|
|
287
|
+
// If you *really* want to enforce the "no longs" assumption, uncomment:
|
|
288
|
+
//
|
|
289
|
+
// if (bytes[4] | bytes[5] | bytes[6] | bytes[7]) {
|
|
290
|
+
// throw new Error("High 32 bits are not zero; expected a 32-bit value stored in 64-bit field.");
|
|
291
|
+
// }
|
|
292
|
+
// Reconstruct from the low 4 bytes (little-endian)
|
|
293
|
+
return (bytes[0] +
|
|
294
|
+
(bytes[1] << 8) +
|
|
295
|
+
(bytes[2] << 16) +
|
|
296
|
+
(bytes[3] * 0x1000000) // avoids sign issues of << 24
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import BaseTideRequest from "./BaseTideRequest";
|
|
2
|
+
export declare class BasicCustomRequest extends BaseTideRequest {
|
|
3
|
+
id(): string;
|
|
4
|
+
}
|
|
5
|
+
export declare class DynamicPayloadCustomRequest extends BaseTideRequest {
|
|
6
|
+
id(): string;
|
|
7
|
+
}
|
|
8
|
+
export declare class DynamicPayloadApprovedCustomRequest extends BaseTideRequest {
|
|
9
|
+
customInfo: CustomInfo | undefined;
|
|
10
|
+
constructor(name: string, version: string, authFlow: string, humanReadableName: string, additionalInfo: any, dyanmicData: Uint8Array);
|
|
11
|
+
id(): string;
|
|
12
|
+
getAdditionalInfoSupplied(): any;
|
|
13
|
+
}
|
|
14
|
+
interface CustomInfo {
|
|
15
|
+
humanReadableName: string;
|
|
16
|
+
additionalInfo: any;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=CustomTideRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomTideRequest.d.ts","sourceRoot":"","sources":["../../Models/CustomTideRequest.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAEhD,qBAAa,kBAAmB,SAAQ,eAAe;IACnD,EAAE,IAAI,MAAM;CAGf;AAED,qBAAa,2BAA4B,SAAQ,eAAe;IAC5D,EAAE,IAAI,MAAM;CAGf;AAED,qBAAa,mCAAoC,SAAQ,eAAe;IACpE,UAAU,EAAE,UAAU,GAAG,SAAS,CAAC;gBAEvB,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,WAAW,EAAE,UAAU;IAQpI,EAAE,IAAI,MAAM;IAIZ,yBAAyB,IAAI,GAAG;CAInC;AACD,UAAU,UAAU;IAChB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,GAAG,CAAC;CACvB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { StringFromUint8Array, StringToUint8Array } from "../Cryptide/Serialization";
|
|
2
|
+
import BaseTideRequest from "./BaseTideRequest";
|
|
3
|
+
export class BasicCustomRequest extends BaseTideRequest {
|
|
4
|
+
id() {
|
|
5
|
+
return `BasicCustom<${this.name}>:BasicCustom<${this.version}>`;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export class DynamicPayloadCustomRequest extends BaseTideRequest {
|
|
9
|
+
id() {
|
|
10
|
+
return `DynamicCustom<${this.name}>:DynamicCustom<${this.version}>`;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class DynamicPayloadApprovedCustomRequest extends BaseTideRequest {
|
|
14
|
+
constructor(name, version, authFlow, humanReadableName, additionalInfo, dyanmicData) {
|
|
15
|
+
const customInfo = {
|
|
16
|
+
humanReadableName: humanReadableName,
|
|
17
|
+
additionalInfo: additionalInfo
|
|
18
|
+
};
|
|
19
|
+
super(name, version, authFlow, StringToUint8Array(JSON.stringify(customInfo)), dyanmicData);
|
|
20
|
+
}
|
|
21
|
+
id() {
|
|
22
|
+
return `DynamicApprovedCustom<${this.name}>:DynamicApprovedCustom<${this.version}>`;
|
|
23
|
+
}
|
|
24
|
+
getAdditionalInfoSupplied() {
|
|
25
|
+
if (this.draft.length > 0)
|
|
26
|
+
return JSON.parse(StringFromUint8Array(this.draft))["additionalInfo"];
|
|
27
|
+
else
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Datum.d.ts","sourceRoot":"","sources":["../../Models/Datum.ts"],"names":[],"mappings":"AAoBA,MAAM,CAAC,OAAO,OAAO,KAAK;IACtB,IAAI,EAAE,UAAU,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;gBAEA,IAAI,EAAE,MAAM,GAAG,UAAU,EAAE,GAAG,EAAE,MAAM;IAIlD,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG;IAGzB,QAAQ;;;;CAMX"}
|
|
@@ -0,0 +1,33 @@
|
|
|
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, bytesToBase64 } from "../Cryptide/Serialization";
|
|
18
|
+
// FieldData on Heimdall turns into Datum on enclave
|
|
19
|
+
export default class Datum {
|
|
20
|
+
constructor(Data, Tag) {
|
|
21
|
+
this.data = typeof (Data) == "string" ? base64ToBytes(Data) : Data;
|
|
22
|
+
this.tag = Tag;
|
|
23
|
+
}
|
|
24
|
+
static fromJSON(json) {
|
|
25
|
+
return new Datum(json.Data, json.Tag);
|
|
26
|
+
}
|
|
27
|
+
toObject() {
|
|
28
|
+
return {
|
|
29
|
+
Data: bytesToBase64(this.data),
|
|
30
|
+
Tag: this.tag
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Ed25519PublicComponent } from "../Cryptide/Components/Schemes/Ed25519/Ed25519Components";
|
|
2
|
+
import TideKey from "../Cryptide/TideKey";
|
|
3
|
+
declare class DokenPayload {
|
|
4
|
+
sessionKey: any;
|
|
5
|
+
tideuserkey: any;
|
|
6
|
+
vuid: any;
|
|
7
|
+
homeOrk: any;
|
|
8
|
+
exp: any;
|
|
9
|
+
aud: any;
|
|
10
|
+
realm_access: any;
|
|
11
|
+
resource_access: any;
|
|
12
|
+
constructor(json: any);
|
|
13
|
+
serialize(): string;
|
|
14
|
+
}
|
|
15
|
+
export declare class Doken {
|
|
16
|
+
dataRef: string;
|
|
17
|
+
header: any;
|
|
18
|
+
payload: DokenPayload;
|
|
19
|
+
signature: Uint8Array;
|
|
20
|
+
private parts;
|
|
21
|
+
constructor(data: string);
|
|
22
|
+
isExpired(): boolean;
|
|
23
|
+
setNewSessionKey(sessionKey: string): void;
|
|
24
|
+
setNewSignature(sig: Uint8Array): void;
|
|
25
|
+
validate(sessionKeyToCheck?: TideKey): {
|
|
26
|
+
success: boolean;
|
|
27
|
+
reason?: string;
|
|
28
|
+
};
|
|
29
|
+
verify(vendorPublic: Ed25519PublicComponent): Promise<any>;
|
|
30
|
+
serialize(): string;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=Doken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Doken.d.ts","sourceRoot":"","sources":["../../Models/Doken.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0DAA0D,CAAC;AAElG,OAAO,OAAO,MAAM,qBAAqB,CAAC;AAI1C,cAAM,YAAY;IACd,UAAU,EAAE,GAAG,CAAC;IAChB,WAAW,EAAE,GAAG,CAAC;IACjB,IAAI,EAAE,GAAG,CAAC;IACV,OAAO,EAAE,GAAG,CAAC;IACb,GAAG,EAAE,GAAG,CAAC;IACT,GAAG,EAAE,GAAG,CAAC;IACT,YAAY,EAAE,GAAG,CAAC;IAClB,eAAe,EAAE,GAAG,CAAC;gBAET,IAAI,EAAE,GAAG;IAiCrB,SAAS;CAYZ;AAED,qBAAa,KAAK;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,GAAG,CAAC;IACZ,OAAO,EAAE,YAAY,CAAC;IACtB,SAAS,EAAE,UAAU,CAAC;IACtB,OAAO,CAAC,KAAK,CAAW;gBAEZ,IAAI,EAAE,MAAM;IAWxB,SAAS,IAAI,OAAO;IAIpB,gBAAgB,CAAC,UAAU,EAAE,MAAM;IAgBnC,eAAe,CAAC,GAAG,EAAE,UAAU;IAQ/B,QAAQ,CAAC,iBAAiB,GAAE,OAAc,GAAG;QAAC,OAAO,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAC;IAkB1E,MAAM,CAAC,YAAY,EAAE,sBAAsB;IAIjD,SAAS,IAAI,MAAM;CAGtB"}
|
|
@@ -0,0 +1,133 @@
|
|
|
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 { Utils } from "../index";
|
|
18
|
+
import { BaseComponent } from "../Cryptide/Components/BaseComponent";
|
|
19
|
+
import { Ed25519PublicComponent } from "../Cryptide/Components/Schemes/Ed25519/Ed25519Components";
|
|
20
|
+
import { base64ToBase64Url, base64ToBytes, base64UrlToBase64, bytesToBase64, StringFromUint8Array, StringToUint8Array } from "../Cryptide/Serialization";
|
|
21
|
+
import TideKey from "../Cryptide/TideKey";
|
|
22
|
+
import { CurrentTime } from "../Tools/Utils";
|
|
23
|
+
// Define DokenPayload class first so it can be used in Doken constructor
|
|
24
|
+
class DokenPayload {
|
|
25
|
+
constructor(json) {
|
|
26
|
+
var s = BaseComponent.DeserializeComponent(json["t.ssk"]);
|
|
27
|
+
if (s instanceof Ed25519PublicComponent) {
|
|
28
|
+
this.sessionKey = s;
|
|
29
|
+
}
|
|
30
|
+
else
|
|
31
|
+
throw Error("Unexpected session key type");
|
|
32
|
+
var u = BaseComponent.DeserializeComponent(json["tideuserkey"]);
|
|
33
|
+
if (u instanceof Ed25519PublicComponent) {
|
|
34
|
+
this.tideuserkey = u;
|
|
35
|
+
}
|
|
36
|
+
else
|
|
37
|
+
throw Error("Unexpected tide user key type");
|
|
38
|
+
if (typeof json.vuid === "string")
|
|
39
|
+
this.vuid = json.vuid;
|
|
40
|
+
else
|
|
41
|
+
throw Error("Expected vuid to be string");
|
|
42
|
+
if (typeof json["t.uho"] === "string")
|
|
43
|
+
this.homeOrk = json["t.uho"];
|
|
44
|
+
else
|
|
45
|
+
throw Error("Expected user home to be string");
|
|
46
|
+
// Will be affected by 2032 problem
|
|
47
|
+
if (typeof json.exp === "number")
|
|
48
|
+
this.exp = json.exp;
|
|
49
|
+
else
|
|
50
|
+
throw Error("Expected exp to be a number");
|
|
51
|
+
if (typeof json.aud === "string")
|
|
52
|
+
this.aud = json.aud;
|
|
53
|
+
else
|
|
54
|
+
throw Error("Expected aud to be string");
|
|
55
|
+
if (typeof json.realm_access === "object")
|
|
56
|
+
this.realm_access = json.realm_access;
|
|
57
|
+
else if (!json.realm_access)
|
|
58
|
+
this.realm_access = null;
|
|
59
|
+
else
|
|
60
|
+
throw Error("Expected realm_access to be string");
|
|
61
|
+
if (typeof json.resource_access === "object")
|
|
62
|
+
this.resource_access = json.resource_access;
|
|
63
|
+
else if (!json.resource_access)
|
|
64
|
+
this.resource_access = null;
|
|
65
|
+
else
|
|
66
|
+
throw Error("Expected resource_access to be string");
|
|
67
|
+
}
|
|
68
|
+
serialize() {
|
|
69
|
+
return JSON.stringify({
|
|
70
|
+
"tideuserkey": this.tideuserkey.Serialize().ToString(),
|
|
71
|
+
"t.ssk": this.sessionKey.Serialize().ToString(),
|
|
72
|
+
"vuid": this.vuid,
|
|
73
|
+
"t.uho": this.homeOrk,
|
|
74
|
+
"exp": this.exp,
|
|
75
|
+
"aud": this.aud,
|
|
76
|
+
"realm_access": this.realm_access,
|
|
77
|
+
"resource_access": this.resource_access
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export class Doken {
|
|
82
|
+
constructor(data) {
|
|
83
|
+
const parts = data.split(".");
|
|
84
|
+
if (parts.length != 3)
|
|
85
|
+
throw Error("Doken must be a 3 part token (including signature)");
|
|
86
|
+
this.parts = parts;
|
|
87
|
+
this.dataRef = data.slice(0);
|
|
88
|
+
this.header = JSON.parse(StringFromUint8Array(base64ToBytes(base64UrlToBase64(parts[0]))));
|
|
89
|
+
this.payload = new DokenPayload(JSON.parse(StringFromUint8Array(base64ToBytes(base64UrlToBase64(parts[1])))));
|
|
90
|
+
this.signature = base64ToBytes(base64UrlToBase64(parts[2]));
|
|
91
|
+
}
|
|
92
|
+
isExpired() {
|
|
93
|
+
return this.payload.exp < CurrentTime();
|
|
94
|
+
}
|
|
95
|
+
setNewSessionKey(sessionKey) {
|
|
96
|
+
const temp = this.dataRef.split(".");
|
|
97
|
+
let payload = StringFromUint8Array(base64ToBytes(base64UrlToBase64(this.parts[1])));
|
|
98
|
+
payload = payload.replace(/("t.ssk"\s*:\s*)"[^"]*"/, `$1"${sessionKey}"`);
|
|
99
|
+
// WE DO ALL THESE MANUAL UPDATES BECAUSE JAVASCRIPT DOES NOT GUARANTEE ORDER IN JSON
|
|
100
|
+
// SINCE WE DON'T SEND THE DOKEN TO GET SIGNED, WE CONTRCUST THE MESSAGE HERE
|
|
101
|
+
// WE NEED TO ENSURE ITS THE SAME THING THE ORK SIGNS
|
|
102
|
+
this.dataRef = temp[0] + "." + base64ToBase64Url(bytesToBase64(StringToUint8Array(payload))) + (temp.length > 2 ? "." + temp[2] : ""); // update encoded string
|
|
103
|
+
this.payload.sessionKey = BaseComponent.DeserializeComponent(sessionKey); // update session key object in payload
|
|
104
|
+
}
|
|
105
|
+
setNewSignature(sig) {
|
|
106
|
+
this.signature = sig.slice(); // update sig object
|
|
107
|
+
const temp = this.dataRef.split(".");
|
|
108
|
+
this.dataRef = temp[0] + "." + temp[1] + "." + base64ToBase64Url(bytesToBase64(this.signature)); // update dataref object
|
|
109
|
+
}
|
|
110
|
+
validate(sessionKeyToCheck = null) {
|
|
111
|
+
// When an error is thrown - its a criticial error so the whole page should stop
|
|
112
|
+
// But if validation just fails, then we return false with a reason why
|
|
113
|
+
if (this.header.alg != "EdDSA")
|
|
114
|
+
throw Error("Doken header alg expected to be EdDSA but got " + this.header.alg);
|
|
115
|
+
if (this.header.typ != "doken")
|
|
116
|
+
throw Error("Doken header typ expected to be doken but got " + this.header.typ);
|
|
117
|
+
// Check expiry
|
|
118
|
+
if (Utils.CurrentTime() > this.payload.exp)
|
|
119
|
+
return { success: false, reason: "expired" };
|
|
120
|
+
// Check session key matches
|
|
121
|
+
if (sessionKeyToCheck) {
|
|
122
|
+
if (!sessionKeyToCheck.get_public_component().Equals(this.payload.sessionKey))
|
|
123
|
+
return { success: false, reason: `sessionkey mismatch. actual: ${sessionKeyToCheck.get_public_component().Serialize().ToString()}. expected: ${this.payload.sessionKey.Serialize().ToString()}` };
|
|
124
|
+
}
|
|
125
|
+
return { success: true };
|
|
126
|
+
}
|
|
127
|
+
async verify(vendorPublic) {
|
|
128
|
+
return new TideKey(vendorPublic).verify(StringToUint8Array(this.dataRef), this.signature);
|
|
129
|
+
}
|
|
130
|
+
serialize() {
|
|
131
|
+
return this.dataRef;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import KeyInfo from "./Infos/KeyInfo";
|
|
2
|
+
export default class EnclaveEntry {
|
|
3
|
+
username: string;
|
|
4
|
+
persona: string;
|
|
5
|
+
expired: bigint;
|
|
6
|
+
userInfo: KeyInfo;
|
|
7
|
+
orksBitwise: (0 | 1)[];
|
|
8
|
+
selfRequesti: string[];
|
|
9
|
+
sessKey: Uint8Array;
|
|
10
|
+
constructor(username: string, persona: string, expired: bigint, userInfo: KeyInfo, orksBitwise: (0 | 1)[], selfRequesti: string[], sessKey: Uint8Array);
|
|
11
|
+
toString(): string;
|
|
12
|
+
static from(data: string): EnclaveEntry;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=EnclaveEntry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnclaveEntry.d.ts","sourceRoot":"","sources":["../../Models/EnclaveEntry.ts"],"names":[],"mappings":"AAkBA,OAAO,OAAO,MAAM,iBAAiB,CAAC;AACtC,MAAM,CAAC,OAAO,OAAO,YAAY;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;IACvB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,OAAO,EAAE,UAAU,CAAC;gBAER,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,UAAU;IAStJ,QAAQ;IAWR,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM;CAS3B"}
|
|
@@ -0,0 +1,49 @@
|
|
|
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, bytesToBase64 } from "../Cryptide/Serialization";
|
|
18
|
+
import KeyInfo from "./Infos/KeyInfo";
|
|
19
|
+
export default class EnclaveEntry {
|
|
20
|
+
constructor(username, persona, expired, userInfo, orksBitwise, selfRequesti, sessKey) {
|
|
21
|
+
this.username = username;
|
|
22
|
+
this.persona = persona;
|
|
23
|
+
this.expired = expired;
|
|
24
|
+
this.userInfo = userInfo;
|
|
25
|
+
this.orksBitwise = orksBitwise;
|
|
26
|
+
this.selfRequesti = selfRequesti;
|
|
27
|
+
this.sessKey = sessKey;
|
|
28
|
+
}
|
|
29
|
+
toString() {
|
|
30
|
+
return JSON.stringify({
|
|
31
|
+
username: this.username,
|
|
32
|
+
persona: this.persona,
|
|
33
|
+
expired: this.expired.toString(),
|
|
34
|
+
userInfo: this.userInfo.toNativeTypeObject(),
|
|
35
|
+
orksBitwise: JSON.stringify(this.orksBitwise),
|
|
36
|
+
selfRequesti: this.selfRequesti,
|
|
37
|
+
sessKey: bytesToBase64(this.sessKey)
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
static from(data) {
|
|
41
|
+
const json = JSON.parse(data);
|
|
42
|
+
const expired = BigInt(json.expired);
|
|
43
|
+
const userInfo = KeyInfo.fromNativeTypeObject(json.userInfo); // includes uid + gCMK, ork URL + id + pubs
|
|
44
|
+
const orksBitwise = JSON.parse(json.orksBitwise);
|
|
45
|
+
const selfRequesti = json.selfRequesti;
|
|
46
|
+
const sessKey = base64ToBytes(json.sessKey);
|
|
47
|
+
return new EnclaveEntry(json.username, json.persona, expired, userInfo, orksBitwise, selfRequesti, sessKey);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Point } from "../../Cryptide/Ed25519";
|
|
2
|
+
import OrkInfo from "./OrkInfo";
|
|
3
|
+
export default class KeyInfo {
|
|
4
|
+
UserId: string;
|
|
5
|
+
UserPublic: Point;
|
|
6
|
+
UserM: string;
|
|
7
|
+
OrkInfo: OrkInfo[];
|
|
8
|
+
constructor(userId: string, userPublic: Point, userM: string, orkInfo: OrkInfo[]);
|
|
9
|
+
toString(): string;
|
|
10
|
+
toNativeTypeObject(): {
|
|
11
|
+
UserId: string;
|
|
12
|
+
UserPublic: string;
|
|
13
|
+
UserM: string;
|
|
14
|
+
OrkInfos: {
|
|
15
|
+
Id: string;
|
|
16
|
+
PublicKey: string;
|
|
17
|
+
URL: string;
|
|
18
|
+
PaymentPublicKey: string;
|
|
19
|
+
}[];
|
|
20
|
+
};
|
|
21
|
+
static from(data: string): KeyInfo;
|
|
22
|
+
static fromNativeTypeObject(json: any): KeyInfo;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=KeyInfo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyInfo.d.ts","sourceRoot":"","sources":["../../../Models/Infos/KeyInfo.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,OAAO,MAAM,WAAW,CAAC;AAEhC,MAAM,CAAC,OAAO,OAAO,OAAO;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,KAAK,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,EAAE,CAAC;gBAEP,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE;IAOhF,QAAQ;IASR,kBAAkB;;;;;;;;;;;IASlB,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM;IAOxB,MAAM,CAAC,oBAAoB,CAAC,IAAI,EAAE,GAAG;CAGxC"}
|