@ethernity-cloud/sdk-js 1.1.0
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 +661 -0
- package/README.md +185 -0
- package/build.js +22 -0
- package/init.js +301 -0
- package/nodenithy/build/las/Dockerfile +5 -0
- package/nodenithy/build/securelock/Dockerfile.tmpl +65 -0
- package/nodenithy/build/securelock/scripts/binary-fs-build.sh +28 -0
- package/nodenithy/build/securelock/src/.env +3 -0
- package/nodenithy/build/securelock/src/etny_crypto.js +201 -0
- package/nodenithy/build/securelock/src/etny_exec.js +65 -0
- package/nodenithy/build/securelock/src/image_registry_abi.js +808 -0
- package/nodenithy/build/securelock/src/models.js +261 -0
- package/nodenithy/build/securelock/src/package.json +40 -0
- package/nodenithy/build/securelock/src/pox_abi.js +1491 -0
- package/nodenithy/build/securelock/src/securelock.js.tmpl +421 -0
- package/nodenithy/build/securelock/src/swift_stream_service.js +147 -0
- package/nodenithy/build/securelock/src/task_status.js +15 -0
- package/nodenithy/build/securelock/src/wallet.js +29 -0
- package/nodenithy/build/squash/Dockerfile +7 -0
- package/nodenithy/build/trustedzone/Dockerfile.tmpl +57 -0
- package/nodenithy/build/trustedzone/scripts/binary-fs-build.sh +22 -0
- package/nodenithy/build/trustedzone/src/.env +3 -0
- package/nodenithy/build/trustedzone/src/etny_crypto.js +202 -0
- package/nodenithy/build/trustedzone/src/etny_exec.js +54 -0
- package/nodenithy/build/trustedzone/src/image_registry_abi.js +808 -0
- package/nodenithy/build/trustedzone/src/models.js +261 -0
- package/nodenithy/build/trustedzone/src/package.json +40 -0
- package/nodenithy/build/trustedzone/src/pox_abi.js +1491 -0
- package/nodenithy/build/trustedzone/src/swift_stream_service.js +147 -0
- package/nodenithy/build/trustedzone/src/task_status.js +15 -0
- package/nodenithy/build/trustedzone/src/test.js +44 -0
- package/nodenithy/build/trustedzone/src/trustedzone.js.tmpl +508 -0
- package/nodenithy/build/trustedzone/src/wallet.js +28 -0
- package/nodenithy/build/validator/Dockerfile +58 -0
- package/nodenithy/build/validator/package-lock.json +6 -0
- package/nodenithy/build/validator/scripts/binary-fs-build.sh +19 -0
- package/nodenithy/build/validator/src/.env +3 -0
- package/nodenithy/build/validator/src/cert.pem +5 -0
- package/nodenithy/build/validator/src/etny_crypto.js +204 -0
- package/nodenithy/build/validator/src/etny_exec.js +52 -0
- package/nodenithy/build/validator/src/image_registry_abi.js +808 -0
- package/nodenithy/build/validator/src/key.pem +6 -0
- package/nodenithy/build/validator/src/models.js +261 -0
- package/nodenithy/build/validator/src/package-lock.json +2498 -0
- package/nodenithy/build/validator/src/package.json +40 -0
- package/nodenithy/build/validator/src/pox_abi.js +1491 -0
- package/nodenithy/build/validator/src/swift_stream_service.js +147 -0
- package/nodenithy/build/validator/src/task_status.js +15 -0
- package/nodenithy/build/validator/src/test.js +44 -0
- package/nodenithy/build/validator/src/trustedzone.js +613 -0
- package/nodenithy/build/validator/src/validator_abi.js +834 -0
- package/nodenithy/build/validator/src/wallet.js +28 -0
- package/nodenithy/build.js +184 -0
- package/nodenithy/build.mjs +179 -0
- package/nodenithy/build.sh +161 -0
- package/nodenithy/ipfs.js +135 -0
- package/nodenithy/ipfs.mjs +551 -0
- package/nodenithy/public/favicon.ico +0 -0
- package/nodenithy/public/index.html +43 -0
- package/nodenithy/public/logo192.png +0 -0
- package/nodenithy/public/logo512.png +0 -0
- package/nodenithy/public/manifest.json +25 -0
- package/nodenithy/public/robots.txt +3 -0
- package/nodenithy/run/__pycache__/swift_stream_service.cpython-312.pyc +0 -0
- package/nodenithy/run/app/input.txt +4 -0
- package/nodenithy/run/app/payload.js +4 -0
- package/nodenithy/run/docker-compose-final.yml.tmpl +65 -0
- package/nodenithy/run/docker-compose-swift-stream.yml +17 -0
- package/nodenithy/run/docker-compose.yml.tmpl +76 -0
- package/nodenithy/run/etny-securelock-test.yaml.tpl +46 -0
- package/nodenithy/run/etny-trustedzone-test.yaml.tpl +45 -0
- package/nodenithy/run/git.sh +22 -0
- package/nodenithy/run/image_registry.abi +1 -0
- package/nodenithy/run/image_registry.js +372 -0
- package/nodenithy/run/image_registry.py +327 -0
- package/nodenithy/run/image_registry_runner.py +71 -0
- package/nodenithy/run/ipfs.sh +58 -0
- package/nodenithy/run/ipfs_pre.sh +75 -0
- package/nodenithy/run/public_key_service.js +90 -0
- package/nodenithy/run/public_key_service.py +107 -0
- package/nodenithy/run/swift_stream_service.py +212 -0
- package/nodenithy/run/swiftstream.py +37 -0
- package/nodenithy/run/swiftstream1.py +27 -0
- package/nodenithy/run.js +538 -0
- package/nodenithy/run.sh +277 -0
- package/nodenithy/scripts/build-ipfs-upload.sh +23 -0
- package/nodenithy/scripts/build.sh +40 -0
- package/nodenithy/scripts/ipfs-daemon.sh +7 -0
- package/nodenithy/scripts/run.sh +50 -0
- package/nodenithy/src/App.css +57 -0
- package/nodenithy/src/ec_helloworld_example.js +64 -0
- package/nodenithy/src/index.css +13 -0
- package/nodenithy/src/index.js +17 -0
- package/nodenithy/src/preStart.js +45 -0
- package/nodenithy/src/preStart.mjs +57 -0
- package/nodenithy/src/reportWebVitals.js +13 -0
- package/nodenithy/src/serverless/backend.js +5 -0
- package/package.json +48 -0
- package/postinstall.js +34 -0
- package/publish.js +126 -0
- package/pynithy/build/docker-compose.yml +68 -0
- package/pynithy/build/las/Dockerfile +11 -0
- package/pynithy/build/las/src/etny_entrypoint.sh +6 -0
- package/pynithy/build/las/src/las_entrypoint.sh +26 -0
- package/pynithy/build/scripts/binary-fs-build.sh +28 -0
- package/pynithy/build/securelock/Dockerfile.tmpl +78 -0
- package/pynithy/build/securelock/scripts/binary-fs-build.sh +41 -0
- package/pynithy/build/securelock/src/app/.env +5 -0
- package/pynithy/build/securelock/src/app/cert1-ca1-clean.crt +10 -0
- package/pynithy/build/securelock/src/app/cert1-ca1-clean.key +6 -0
- package/pynithy/build/securelock/src/app/enclave_pub_cert.pem +10 -0
- package/pynithy/build/securelock/src/app/input.txt +1 -0
- package/pynithy/build/securelock/src/app/payload.py +25 -0
- package/pynithy/build/securelock/src/app/public-cert-clean.pem +10 -0
- package/pynithy/build/securelock/src/app/result.txt +1 -0
- package/pynithy/build/securelock/src/app/transaction.txt +1 -0
- package/pynithy/build/securelock/src/etny_crypto.py +167 -0
- package/pynithy/build/securelock/src/etny_exec.py +79 -0
- package/pynithy/build/securelock/src/image_registry.abi +1 -0
- package/pynithy/build/securelock/src/key_generation.py +17 -0
- package/pynithy/build/securelock/src/models.py +176 -0
- package/pynithy/build/securelock/src/pox.abi +1489 -0
- package/pynithy/build/securelock/src/securelock.py.tmpl +411 -0
- package/pynithy/build/securelock/src/swift_stream_service.py +186 -0
- package/pynithy/build/trustedzone/Dockerfile.tmpl +56 -0
- package/pynithy/build/trustedzone/scripts/binary-fs-build.sh +32 -0
- package/pynithy/build/trustedzone/src/app/.env +5 -0
- package/pynithy/build/trustedzone/src/app/cert1-ca1-clean.crt +10 -0
- package/pynithy/build/trustedzone/src/app/cert1-ca1-clean.key +6 -0
- package/pynithy/build/trustedzone/src/app/enclave_pub_cert.pem +10 -0
- package/pynithy/build/trustedzone/src/app/input.txt +1 -0
- package/pynithy/build/trustedzone/src/app/payload.py +25 -0
- package/pynithy/build/trustedzone/src/app/public-cert-clean.pem +10 -0
- package/pynithy/build/trustedzone/src/app/result.txt +1 -0
- package/pynithy/build/trustedzone/src/app/securelock.crt +10 -0
- package/pynithy/build/trustedzone/src/app/transaction.txt +1 -0
- package/pynithy/build/trustedzone/src/app/trustedzone.crt +10 -0
- package/pynithy/build/trustedzone/src/etny_crypto.py +188 -0
- package/pynithy/build/trustedzone/src/etny_exec.py +56 -0
- package/pynithy/build/trustedzone/src/formatter.py +42 -0
- package/pynithy/build/trustedzone/src/image_registry.abi +1 -0
- package/pynithy/build/trustedzone/src/key_generation.py +17 -0
- package/pynithy/build/trustedzone/src/models.py +176 -0
- package/pynithy/build/trustedzone/src/pox.abi +1489 -0
- package/pynithy/build/trustedzone/src/swift_stream_service.py +186 -0
- package/pynithy/build/trustedzone/src/trustedzone.py.tmpl +460 -0
- package/pynithy/build.mjs +179 -0
- package/pynithy/docker-compose.yml +0 -0
- package/pynithy/ipfs.mjs +244 -0
- package/pynithy/public/favicon.ico +0 -0
- package/pynithy/public/index.html +43 -0
- package/pynithy/public/logo192.png +0 -0
- package/pynithy/public/logo512.png +0 -0
- package/pynithy/public/manifest.json +25 -0
- package/pynithy/public/robots.txt +3 -0
- package/pynithy/run/certs/cert.pem +31 -0
- package/pynithy/run/certs/challenge.crt +10 -0
- package/pynithy/run/certs/key.pem +52 -0
- package/pynithy/run/docker-compose-final.yml +59 -0
- package/pynithy/run/docker-compose-final.yml.tmpl +59 -0
- package/pynithy/run/docker-compose-swift-stream.yml +27 -0
- package/pynithy/run/docker-compose-swift-stream.yml.tmpl +27 -0
- package/pynithy/run/docker-compose.yml +55 -0
- package/pynithy/run/docker-compose.yml.tmpl +55 -0
- package/pynithy/run/etny-pynity-test.yaml.tpl +46 -0
- package/pynithy/run/etny-securelock-test.yaml.tpl +46 -0
- package/pynithy/run/etny-trustedzone-test.yaml.tpl +46 -0
- package/pynithy/run/git.sh +22 -0
- package/pynithy/run/image_registry.abi +1 -0
- package/pynithy/run/image_registry.js +372 -0
- package/pynithy/run/image_registry.py +139 -0
- package/pynithy/run/image_registry_runner.py +45 -0
- package/pynithy/run/ipfs.sh +89 -0
- package/pynithy/run/public_key_service.js +90 -0
- package/pynithy/run/swiftstream.py +28 -0
- package/pynithy/run.js +538 -0
- package/pynithy/src/App.css +57 -0
- package/pynithy/src/ec_helloworld_example.js +64 -0
- package/pynithy/src/index.css +13 -0
- package/pynithy/src/index.js +17 -0
- package/pynithy/src/preStart.mjs +57 -0
- package/pynithy/src/reportWebVitals.js +13 -0
- package/pynithy/src/serverless/__init__.py +0 -0
- package/pynithy/src/serverless/backend.py +2 -0
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
const Web3 = require('web3');
|
|
2
|
+
const { ethers } = require('ethers');
|
|
3
|
+
const { Account } = require('eth-lib/lib/account');
|
|
4
|
+
const { config } = require('dotenv');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
|
|
8
|
+
config();
|
|
9
|
+
|
|
10
|
+
const PRIVATE_KEY = process.env.PRIVATE_KEY || "";
|
|
11
|
+
let BLOCKCHAIN_NETWORK = process.env.BLOCKCHAIN_NETWORK || "Bloxberg_Testnet";
|
|
12
|
+
let NETWORK_RPC = "https://bloxberg.ethernity.cloud";
|
|
13
|
+
let IMAGE_REGISTRY_ADDRESS = "0x15D73a742529C3fb11f3FA32EF7f0CC3870ACA31"; // bloxberg testnet
|
|
14
|
+
let CHAIN_ID = 8995;
|
|
15
|
+
let GAS = 9000000;
|
|
16
|
+
let GAS_PRICE = 1;
|
|
17
|
+
|
|
18
|
+
function setVars(network = "") {
|
|
19
|
+
if (BLOCKCHAIN_NETWORK.includes("Bloxberg")) {
|
|
20
|
+
IMAGE_REGISTRY_ADDRESS = "0x15D73a742529C3fb11f3FA32EF7f0CC3870ACA31";
|
|
21
|
+
} else if (BLOCKCHAIN_NETWORK.includes("Polygon")) {
|
|
22
|
+
if (BLOCKCHAIN_NETWORK.includes("Mainnet")) {
|
|
23
|
+
NETWORK_RPC = "https://polygon-rpc.com";
|
|
24
|
+
IMAGE_REGISTRY_ADDRESS = "0x689f3806874d3c8A973f419a4eB24e6fBA7E830F";
|
|
25
|
+
CHAIN_ID = 137;
|
|
26
|
+
GAS = 20000000;
|
|
27
|
+
GAS_PRICE = 40500500010;
|
|
28
|
+
} else {
|
|
29
|
+
NETWORK_RPC = "https://rpc-amoy.polygon.technology";
|
|
30
|
+
IMAGE_REGISTRY_ADDRESS = "0xF7F4eEb3d9a64387F4AcEb6d521b948E6E2fB049";
|
|
31
|
+
CHAIN_ID = 80002;
|
|
32
|
+
GAS = 20000000;
|
|
33
|
+
GAS_PRICE = 1300000010;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
setVars();
|
|
39
|
+
|
|
40
|
+
function isStringPrivateKey(privateKey) {
|
|
41
|
+
try {
|
|
42
|
+
let key = privateKey;
|
|
43
|
+
if (!key.startsWith("0x")) {
|
|
44
|
+
key = `0x${privateKey}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
Web3.eth.accounts.privateKeyToAccount(key);
|
|
48
|
+
return "OK";
|
|
49
|
+
} catch (e) {
|
|
50
|
+
return e.toString();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function checkAccountBalance() {
|
|
55
|
+
try {
|
|
56
|
+
const web3 = new ethers.providers.JsonRpcProvider(NETWORK_RPC);
|
|
57
|
+
const account = new ethers.Wallet(PRIVATE_KEY, this.provider);
|
|
58
|
+
const balance = await web3.getBalance(account.address);
|
|
59
|
+
return Web3.utils.fromWei(balance, 'ether');
|
|
60
|
+
} catch (e) {
|
|
61
|
+
console.error(e);
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
class ImageRegistry {
|
|
67
|
+
constructor() {
|
|
68
|
+
try {
|
|
69
|
+
this.imageRegistryAbi = this.readContractAbi('image_registry.abi');
|
|
70
|
+
this.imageRegistryAddress = IMAGE_REGISTRY_ADDRESS;
|
|
71
|
+
console.log("imageRegistryAddress: ", this.imageRegistryAddress);
|
|
72
|
+
this.provider = new ethers.providers.JsonRpcProvider(NETWORK_RPC);
|
|
73
|
+
|
|
74
|
+
if (PRIVATE_KEY) {
|
|
75
|
+
this.acct = new ethers.Wallet(PRIVATE_KEY, this.provider);
|
|
76
|
+
} else {
|
|
77
|
+
const _privateKey = new ethers.Wallet.createRandom().privateKey;
|
|
78
|
+
this.acct = new ethers.Wallet(_privateKey, this.provider);
|
|
79
|
+
}
|
|
80
|
+
this.imageRegistryContract = new ethers.Contract(
|
|
81
|
+
this.imageRegistryAddress,
|
|
82
|
+
this.imageRegistryAbi,
|
|
83
|
+
this.acct
|
|
84
|
+
);
|
|
85
|
+
} catch (e) {
|
|
86
|
+
console.error(e);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
readContractAbi(contractName) {
|
|
91
|
+
const filePath = path.join(__dirname, contractName);
|
|
92
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async addTrustedZoneCert(certContent, ipfsHash, imageName, dockerComposeHash, enclaveNameTrustedZone, fee) {
|
|
96
|
+
console.log("Adding trusted zone cert to image registry");
|
|
97
|
+
const nonce = await this.provider.getTransactionCount(this.acct.address);
|
|
98
|
+
|
|
99
|
+
const unicornTxn = this.imageRegistryContract.addTrustedZoneImage(
|
|
100
|
+
ipfsHash, certContent, "v3", imageName, dockerComposeHash, enclaveNameTrustedZone, fee
|
|
101
|
+
).send({
|
|
102
|
+
gas: GAS,
|
|
103
|
+
chainId: CHAIN_ID,
|
|
104
|
+
nonce: nonce,
|
|
105
|
+
gasPrice: GAS_PRICE === 1 ? ethers.utils.parseUnits('1', 'mwei') : GAS_PRICE
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
console.log("transaction status: ", receipt.status);
|
|
109
|
+
console.log("transaction receipt: ", receipt);
|
|
110
|
+
if (receipt.status === 1) {
|
|
111
|
+
console.log("Adding trusted zone cert transaction was successful!");
|
|
112
|
+
} else {
|
|
113
|
+
console.log("Adding trusted zone cert transaction was UNSUCCESSFUL!");
|
|
114
|
+
}
|
|
115
|
+
const signedTxn = await this.acct.signTransaction(unicornTxn);
|
|
116
|
+
const receipt = await this.provider.sendTransaction(signedTxn.rawTransaction);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async addSecureLockImageCert(certContent, ipfsHash, imageName, version, dockerComposeHash, enclaveNameSecureLock, fee) {
|
|
120
|
+
try {
|
|
121
|
+
console.log("Adding secure lock image cert to image registry");
|
|
122
|
+
// Fetch current nonce
|
|
123
|
+
if (BLOCKCHAIN_NETWORK.includes("Polygon")) {
|
|
124
|
+
console.log("Polygon Mainnet");
|
|
125
|
+
let nonce = await this.provider.getTransactionCount(this.acct.address, 'pending');
|
|
126
|
+
// Fetch current gas price and increase it
|
|
127
|
+
let gasPrice = await this.provider.getGasPrice();
|
|
128
|
+
gasPrice = gasPrice.mul(ethers.BigNumber.from(110)).div(ethers.BigNumber.from(100));
|
|
129
|
+
const unicornTxn = await this.imageRegistryContract.addImage(
|
|
130
|
+
ipfsHash, certContent, version, imageName, dockerComposeHash, enclaveNameSecureLock, fee,
|
|
131
|
+
{
|
|
132
|
+
nonce: nonce,
|
|
133
|
+
gasPrice: gasPrice,
|
|
134
|
+
});
|
|
135
|
+
// console.log("Transaction: ", unicornTxn);
|
|
136
|
+
const receipt = await this.imageRegistryContract.provider.waitForTransaction(unicornTxn.hash);
|
|
137
|
+
|
|
138
|
+
// console.log("transaction status: ", receipt.status);
|
|
139
|
+
console.log("transaction receipt: ", unicornTxn.hash);
|
|
140
|
+
if (receipt.status === 1) {
|
|
141
|
+
console.log("Adding secure lock image cert transaction was successful!");
|
|
142
|
+
} else {
|
|
143
|
+
// console.log("receipt.status", receipt.status)
|
|
144
|
+
console.log("Image certificates already exist for this image!");
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
const unicornTxn = await this.imageRegistryContract.addImage(
|
|
148
|
+
ipfsHash, certContent, version, imageName, dockerComposeHash, enclaveNameSecureLock, fee);
|
|
149
|
+
// console.log("Transaction: ", unicornTxn);
|
|
150
|
+
const receipt = await this.imageRegistryContract.provider.waitForTransaction(unicornTxn.hash);
|
|
151
|
+
|
|
152
|
+
// console.log("transaction status: ", receipt.status);
|
|
153
|
+
console.log("transaction receipt: ", unicornTxn.hash);
|
|
154
|
+
if (receipt.status === 1) {
|
|
155
|
+
console.log("Adding secure lock image cert transaction was successful!");
|
|
156
|
+
} else {
|
|
157
|
+
// console.log("receipt.status", receipt.status)
|
|
158
|
+
console.log("Image certificates already exist for this image!");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// console.log("this.acct.address: ", this.acct.address);
|
|
163
|
+
// console.log("private key", PRIVATE_KEY);
|
|
164
|
+
// console.log('Getting nonce');
|
|
165
|
+
// const nonce = await this.imageRegistryContract.provider.getTransactionCount(this.acct.address);
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
// const signedTxn = await this.acct.signTransaction(unicornTxn);
|
|
169
|
+
// const receipt = await this.provider.sendTransaction(signedTxn.rawTransaction);
|
|
170
|
+
} catch (e) {
|
|
171
|
+
// console.error(e);
|
|
172
|
+
console.log("Image certificates already exist for this image!");
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async getImagePublicKeyCert(ipfsHash) {
|
|
177
|
+
try {
|
|
178
|
+
console.log("Getting image cert from image registry");
|
|
179
|
+
// console.log("this.acct.address: ", this.acct.address);
|
|
180
|
+
// console.log("private key", PRIVATE_KEY);
|
|
181
|
+
// console.log('Getting nonce');
|
|
182
|
+
// const nonce = await this.imageRegistryContract.provider.getTransactionCount(this.acct.address);
|
|
183
|
+
const unicornTxn = await this.imageRegistryContract.getImageCertPublicKey(ipfsHash);
|
|
184
|
+
console.log("unicornTxn: ", unicornTxn);
|
|
185
|
+
// const receipt = await this.imageRegistryContract.provider.waitForTransaction(unicornTxn.hash);
|
|
186
|
+
|
|
187
|
+
// console.log("transaction status: ", receipt.status);
|
|
188
|
+
// // console.log("transaction receipt: ", unicornTxn);
|
|
189
|
+
// if (receipt.status === 1) {
|
|
190
|
+
// console.log("");
|
|
191
|
+
// } else {
|
|
192
|
+
// console.log("Adding secure lock image cert transaction was UNSUCCESSFUL!");
|
|
193
|
+
// }
|
|
194
|
+
// const signedTxn = await this.acct.signTransaction(unicornTxn);
|
|
195
|
+
// const receipt = await this.provider.sendTransaction(signedTxn.rawTransaction);
|
|
196
|
+
} catch (e) {
|
|
197
|
+
console.error(e);
|
|
198
|
+
console.log("Getting image cert transaction was UNSUCCESSFUL!");
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
async validateSecureLockImageCert(certContent, ipfsHash, imageName, dockerComposeHash, enclaveNameSecureLock, fee) {
|
|
203
|
+
console.log("Validating secure lock image cert in image registry");
|
|
204
|
+
const nonce = await this.provider.getTransactionCount(this.acct.address);
|
|
205
|
+
const unicornTxn = this.imageRegistryContract.validateSecureLockImage(
|
|
206
|
+
ipfsHash, certContent, "v3", imageName, dockerComposeHash, enclaveNameSecureLock, fee
|
|
207
|
+
).send({
|
|
208
|
+
gas: GAS,
|
|
209
|
+
chainId: CHAIN_ID,
|
|
210
|
+
nonce: nonce,
|
|
211
|
+
gasPrice: GAS_PRICE === 1 ? ethers.utils.parseUnits('1', 'mwei') : GAS_PRICE
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
console.log("transaction status: ", receipt.status);
|
|
215
|
+
console.log("transaction receipt: ", receipt);
|
|
216
|
+
if (receipt.status === 1) {
|
|
217
|
+
console.log("Validating secure lock image cert transaction was successful!");
|
|
218
|
+
} else {
|
|
219
|
+
console.log("Validating secure lock image cert transaction was UNSUCCESSFUL!");
|
|
220
|
+
}
|
|
221
|
+
const signedTxn = await this.acct.signTransaction(unicornTxn);
|
|
222
|
+
const receipt = await this.provider.sendTransaction(signedTxn.rawTransaction);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async addSecureLockAndValidateImageCert(certContent, ipfsHash, imageName, dockerComposeHash, enclaveNameSecureLock, fee) {
|
|
226
|
+
console.log("Adding and validating secure lock image cert in image registry");
|
|
227
|
+
const nonce = await this.provider.getTransactionCount(this.acct.address);
|
|
228
|
+
const unicornTxn = this.imageRegistryContract.addSecureLockAndValidateImage(
|
|
229
|
+
ipfsHash, certContent, "v3", imageName, dockerComposeHash, enclaveNameSecureLock, fee
|
|
230
|
+
).send({
|
|
231
|
+
gas: GAS,
|
|
232
|
+
chainId: CHAIN_ID,
|
|
233
|
+
nonce: nonce,
|
|
234
|
+
gasPrice: GAS_PRICE === 1 ? ethers.utils.parseUnits('1', 'mwei') : GAS_PRICE
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
console.log("transaction status: ", receipt.status);
|
|
238
|
+
console.log("transaction receipt: ", receipt);
|
|
239
|
+
if (receipt.status === 1) {
|
|
240
|
+
console.log("Adding and validating secure lock image cert transaction was successful!");
|
|
241
|
+
} else {
|
|
242
|
+
console.log("Adding and validating secure lock image cert transaction was UNSUCCESSFUL!");
|
|
243
|
+
}
|
|
244
|
+
const signedTxn = await this.acct.signTransaction(unicornTxn);
|
|
245
|
+
const receipt = await this.provider.sendTransaction(signedTxn.rawTransaction);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async getTrustedZoneCert(ipfsHash) {
|
|
249
|
+
const cert = await this.imageRegistryContract.getTrustedZoneCert(ipfsHash);
|
|
250
|
+
return cert;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async getSecureLockCert(ipfsHash) {
|
|
254
|
+
const cert = await this.imageRegistryContract.getSecureLockCert(ipfsHash);
|
|
255
|
+
return cert;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async getImageDetails(ipfsHash) {
|
|
259
|
+
try {
|
|
260
|
+
const details = await this.imageRegistryContract.imageDetails(ipfsHash);
|
|
261
|
+
return details;
|
|
262
|
+
} catch (e) {
|
|
263
|
+
return ['', '', ''];
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
async _getLatestImageVersionPublicKey(projectName, version) {
|
|
268
|
+
try {
|
|
269
|
+
// console.log("Getting latest image version public key");
|
|
270
|
+
const publicKey = await this.imageRegistryContract.getLatestImageVersionPublicKey(projectName, version);
|
|
271
|
+
// console.log("public key: ", publicKey);
|
|
272
|
+
return publicKey;
|
|
273
|
+
} catch (e) {
|
|
274
|
+
// console.error(e);
|
|
275
|
+
return ['', '', ''];
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
(async () => {
|
|
281
|
+
try {
|
|
282
|
+
const [networkName, projectName, version, privateKey, action] = process.argv.slice(2);
|
|
283
|
+
if (action === "validateAddress") {
|
|
284
|
+
if (privateKey) {
|
|
285
|
+
console.log(isStringPrivateKey(privateKey));
|
|
286
|
+
}
|
|
287
|
+
process.exit(0);
|
|
288
|
+
}
|
|
289
|
+
if (networkName && projectName) {
|
|
290
|
+
BLOCKCHAIN_NETWORK = networkName;
|
|
291
|
+
}
|
|
292
|
+
setVars(networkName);
|
|
293
|
+
if (action === "checkBalance") {
|
|
294
|
+
const balance = await checkAccountBalance();
|
|
295
|
+
console.log(`${balance} gas`);
|
|
296
|
+
process.exit(0);
|
|
297
|
+
}
|
|
298
|
+
if (action === 'getTrustedZoneCert') {
|
|
299
|
+
const imageRegistry = new ImageRegistry();
|
|
300
|
+
const public = (await imageRegistry._getLatestImageVersionPublicKey(projectName, version))[1]
|
|
301
|
+
console.log(public);
|
|
302
|
+
return public;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const imageRegistry = new ImageRegistry();
|
|
306
|
+
if (action === 'registerSecureLockImage') {
|
|
307
|
+
const secureLock = fs.readFileSync("./registry/certificate.securelock.crt", 'utf8');
|
|
308
|
+
// console.log("SECURELOCK:", secureLock);
|
|
309
|
+
const ipfsHash = process.env.IPFS_HASH || "";
|
|
310
|
+
console.log(`ipfsHash: ${ipfsHash}`);
|
|
311
|
+
const ipfsDockerComposeHash = process.env.IPFS_DOCKER_COMPOSE_HASH || "";
|
|
312
|
+
console.log(`ipfsDockerComposeHash: ${ipfsDockerComposeHash}`);
|
|
313
|
+
const imageName = process.env.PROJECT_NAME || "";
|
|
314
|
+
console.log(`imageName: ${imageName}`);
|
|
315
|
+
const enclaveVersion = process.env.VERSION || "";
|
|
316
|
+
const enclaveNameSecureLock = process.env.ENCLAVE_NAME_SECURELOCK || "";
|
|
317
|
+
console.log(`enclaveNameSecureLock: ${enclaveNameSecureLock}`);
|
|
318
|
+
const fee = process.env.DEVELOPER_FEE || "0";
|
|
319
|
+
console.log(`fee: ${fee}`);
|
|
320
|
+
|
|
321
|
+
// Register the SAME build under two registry version keys:
|
|
322
|
+
// "v3" -> the moving "latest" pointer the runner resolves by
|
|
323
|
+
// default (getLatestImageVersionPublicKey(name,"v3")).
|
|
324
|
+
// This MUST be "v3" (the protocol version), NOT the
|
|
325
|
+
// enclave/template VERSION -- registering under the
|
|
326
|
+
// VERSION (e.g. "21") wrote the pointer where the
|
|
327
|
+
// runner never looks, so it kept using a stale image.
|
|
328
|
+
// <VERSION> -> an immutable per-version entry (e.g. "22") so this
|
|
329
|
+
// exact build can be pinned/rolled back to later.
|
|
330
|
+
// The contract stores each (name,version) channel append-only.
|
|
331
|
+
const versionKeys = ["v3"];
|
|
332
|
+
if (enclaveVersion && enclaveVersion !== "v3") versionKeys.push(enclaveVersion);
|
|
333
|
+
for (const versionKey of versionKeys) {
|
|
334
|
+
console.log(`Registering securelock under version '${versionKey}'`);
|
|
335
|
+
await imageRegistry.addSecureLockImageCert(secureLock, ipfsHash, imageName, versionKey, ipfsDockerComposeHash, enclaveNameSecureLock, fee);
|
|
336
|
+
}
|
|
337
|
+
process.exit(0);
|
|
338
|
+
}
|
|
339
|
+
if (action === 'getImagePublicKey') {
|
|
340
|
+
const ipfsHash = process.env.IPFS_HASH || "";
|
|
341
|
+
await imageRegistry.getImagePublicKeyCert(ipfsHash);
|
|
342
|
+
process.exit(0);
|
|
343
|
+
}
|
|
344
|
+
console.log(`Checking image: '${projectName}' on the ${networkName} blockchain...`);
|
|
345
|
+
const imageHash = (await imageRegistry._getLatestImageVersionPublicKey(projectName, version))[0];
|
|
346
|
+
console.log(`Image hash: ${imageHash}`);
|
|
347
|
+
if (!imageHash) {
|
|
348
|
+
console.log(`Image: '${projectName}' is available on the ${networkName} blockchain.`);
|
|
349
|
+
process.exit(0);
|
|
350
|
+
}
|
|
351
|
+
const imageOwner = (await imageRegistry.getImageDetails(imageHash))[0];
|
|
352
|
+
|
|
353
|
+
if (privateKey) {
|
|
354
|
+
if (isStringPrivateKey(privateKey) === "OK") {
|
|
355
|
+
const account = Account.fromPrivate(privateKey);
|
|
356
|
+
if (imageOwner !== account.address) {
|
|
357
|
+
console.log(`!!! Image: '${projectName}' is owned by '${imageOwner}'.\nYou are not the account holder of the image.\nPlease change the project name and try again.\n`);
|
|
358
|
+
process.exit(1);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (imageOwner) {
|
|
364
|
+
console.log(`Image: '${projectName}' is owned by '${imageOwner}'.\nIf you are not the account holder, you will not be able to publish your project with the current name. Please change the project name and try again.\n`);
|
|
365
|
+
process.exit(0);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
console.log(`Image: '${projectName}' is available on the ${networkName} blockchain.`);
|
|
369
|
+
} catch (e) {
|
|
370
|
+
process.exit(0);
|
|
371
|
+
}
|
|
372
|
+
})();
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import os, sys
|
|
2
|
+
|
|
3
|
+
from web3 import Web3
|
|
4
|
+
from web3.middleware import geth_poa_middleware
|
|
5
|
+
from eth_account import Account
|
|
6
|
+
|
|
7
|
+
from dotenv import load_dotenv
|
|
8
|
+
|
|
9
|
+
load_dotenv()
|
|
10
|
+
|
|
11
|
+
PRIVATE_KEY = os.getenv("PRIVATE_KEY", "")
|
|
12
|
+
|
|
13
|
+
BLOCKCHAIN_NETWORK = os.getenv("BLOCKCHAIN_NETWORK", "Bloxberg_Testnet")
|
|
14
|
+
|
|
15
|
+
NETWORK_RPC = "https://bloxberg.ethernity.cloud"
|
|
16
|
+
IMAGE_REGISTRY_ADDRESS = "0x15D73a742529C3fb11f3FA32EF7f0CC3870ACA31" # Bloxberg
|
|
17
|
+
CHAIN_ID = 8995
|
|
18
|
+
GAS = 9000000
|
|
19
|
+
GAS_PRICE = 1
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def set_vars(network: str = "") -> None:
|
|
23
|
+
global BLOCKCHAIN_NETWORK
|
|
24
|
+
global IMAGE_REGISTRY_ADDRESS
|
|
25
|
+
global NETWORK_RPC
|
|
26
|
+
global CHAIN_ID
|
|
27
|
+
global GAS
|
|
28
|
+
global GAS_PRICE
|
|
29
|
+
if "Bloxberg" in BLOCKCHAIN_NETWORK:
|
|
30
|
+
if "Mainnet" in BLOCKCHAIN_NETWORK:
|
|
31
|
+
IMAGE_REGISTRY_ADDRESS = "0x15D73a742529C3fb11f3FA32EF7f0CC3870ACA31"
|
|
32
|
+
else:
|
|
33
|
+
IMAGE_REGISTRY_ADDRESS = "0x15D73a742529C3fb11f3FA32EF7f0CC3870ACA31"
|
|
34
|
+
elif "Polygon" in BLOCKCHAIN_NETWORK:
|
|
35
|
+
if "Mainnet" in BLOCKCHAIN_NETWORK:
|
|
36
|
+
NETWORK_RPC = "https://polygon-pokt.nodies.app"
|
|
37
|
+
IMAGE_REGISTRY_ADDRESS = "0x689f3806874d3c8A973f419a4eB24e6fBA7E830F"
|
|
38
|
+
CHAIN_ID = 137
|
|
39
|
+
GAS = 20000000
|
|
40
|
+
GAS_PRICE = 40500500010
|
|
41
|
+
else:
|
|
42
|
+
NETWORK_RPC = "https://rpc-amoy.polygon.technology`"
|
|
43
|
+
IMAGE_REGISTRY_ADDRESS = "0xF7F4eEb3d9a64387F4AcEb6d521b948E6E2fB049"
|
|
44
|
+
CHAIN_ID = 80002
|
|
45
|
+
GAS = 20000000
|
|
46
|
+
GAS_PRICE = 1300000010
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
set_vars()
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def is_string_private_key(private_key: str) -> str:
|
|
53
|
+
try:
|
|
54
|
+
_acct = Account.privateKeyToAccount(private_key)
|
|
55
|
+
return "OK"
|
|
56
|
+
except Exception as e:
|
|
57
|
+
return str(e)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def check_acount_balance() -> int:
|
|
61
|
+
try:
|
|
62
|
+
_acct = Account.privateKeyToAccount(PRIVATE_KEY)
|
|
63
|
+
web3_provider = NETWORK_RPC
|
|
64
|
+
w3 = Web3(Web3.HTTPProvider(web3_provider))
|
|
65
|
+
w3.middleware_onion.inject(geth_poa_middleware, layer=0)
|
|
66
|
+
|
|
67
|
+
address = _acct.address
|
|
68
|
+
balance = w3.eth.getBalance(address)
|
|
69
|
+
return Web3.fromWei(balance, "ether") # type: ignore
|
|
70
|
+
except Exception as e:
|
|
71
|
+
print(e)
|
|
72
|
+
return 0
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class ImageRegistry:
|
|
76
|
+
def __init__(self) -> None:
|
|
77
|
+
self.acct = None # type: ignore
|
|
78
|
+
if PRIVATE_KEY:
|
|
79
|
+
self.acct = Account.privateKeyToAccount(PRIVATE_KEY)
|
|
80
|
+
|
|
81
|
+
image_registry_abi = self.__read_contract_abi("image_registry.abi")
|
|
82
|
+
self.image_registry_address = IMAGE_REGISTRY_ADDRESS
|
|
83
|
+
|
|
84
|
+
self.web3_provider = NETWORK_RPC
|
|
85
|
+
self.w3 = Web3(Web3.HTTPProvider(self.web3_provider))
|
|
86
|
+
self.w3.middleware_onion.inject(geth_poa_middleware, layer=0)
|
|
87
|
+
|
|
88
|
+
self.image_registry = self.w3.eth.contract(
|
|
89
|
+
address=self.w3.toChecksumAddress(self.image_registry_address),
|
|
90
|
+
abi=image_registry_abi,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
def __read_contract_abi(self, contract_name: str) -> str:
|
|
94
|
+
f = open(os.path.dirname(os.path.realpath(__file__)) + f"/{contract_name}")
|
|
95
|
+
contract_abi = f.read()
|
|
96
|
+
f.close()
|
|
97
|
+
return contract_abi
|
|
98
|
+
|
|
99
|
+
# (string memory ipfsHash, string memory publicKey, string memory version, string memory imageName, string memory dockerComposeHash)
|
|
100
|
+
def add_trusted_zone_cert(
|
|
101
|
+
self,
|
|
102
|
+
cert_content: str,
|
|
103
|
+
ipfs_hash: str,
|
|
104
|
+
image_name: str,
|
|
105
|
+
docker_compose_hash: str,
|
|
106
|
+
enclave_name_trustedzone: str,
|
|
107
|
+
fee: str,
|
|
108
|
+
) -> None:
|
|
109
|
+
print("Adding trusted zone cert to image registry")
|
|
110
|
+
nonce = self.w3.eth.getTransactionCount(self.acct.address)
|
|
111
|
+
print(f"Nonce: {nonce}")
|
|
112
|
+
print("ipfs_hash: ", ipfs_hash)
|
|
113
|
+
print("cert_content: ", cert_content)
|
|
114
|
+
print("image_name: ", image_name)
|
|
115
|
+
print("docker_compose_hash: ", docker_compose_hash)
|
|
116
|
+
print("enclave_name_trustedzone: ", enclave_name_trustedzone)
|
|
117
|
+
print("fee: ", fee)
|
|
118
|
+
unicorn_txn = self.image_registry.functions.addTrustedZoneImage(
|
|
119
|
+
ipfs_hash,
|
|
120
|
+
cert_content,
|
|
121
|
+
"v3",
|
|
122
|
+
image_name,
|
|
123
|
+
docker_compose_hash,
|
|
124
|
+
enclave_name_trustedzone,
|
|
125
|
+
fee,
|
|
126
|
+
).buildTransaction(
|
|
127
|
+
{
|
|
128
|
+
"gas": GAS,
|
|
129
|
+
"chainId": CHAIN_ID,
|
|
130
|
+
"nonce": nonce,
|
|
131
|
+
"gasPrice": self.w3.toWei("1", "mwei") if GAS_PRICE == 1 else GAS_PRICE,
|
|
132
|
+
}
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
signed_txn = self.w3.eth.account.sign_transaction(
|
|
136
|
+
unicorn_txn, private_key=self.acct.key
|
|
137
|
+
)
|
|
138
|
+
self.w3.eth.sendRawTransaction(signed_txn.rawTransaction)
|
|
139
|
+
# self.transaction = unicorn_tx signed
|
|
140
|
+
hash = self.w3.toHex(self.w3.sha3(signed_txn.rawTransaction))
|
|
141
|
+
|
|
142
|
+
try:
|
|
143
|
+
receipt = self.w3.eth.waitForTransactionReceipt(hash)
|
|
144
|
+
except Exception as e:
|
|
145
|
+
print(f"An error occurred while sending transaction", e)
|
|
146
|
+
raise
|
|
147
|
+
|
|
148
|
+
print("transaction status: ", receipt.status)
|
|
149
|
+
print("transaction receipt: ", receipt)
|
|
150
|
+
if receipt.status == 1:
|
|
151
|
+
print("Adding trusted zone cert transaction was successful!")
|
|
152
|
+
else:
|
|
153
|
+
print("Adding trusted zone cert transaction was UNSUCCESSFUL!")
|
|
154
|
+
|
|
155
|
+
def add_secure_lock_image_cert(
|
|
156
|
+
self,
|
|
157
|
+
cert_content: str,
|
|
158
|
+
ipfs_hash: str,
|
|
159
|
+
image_name: str,
|
|
160
|
+
docker_compose_hash: str,
|
|
161
|
+
enclave_name_securelock: str,
|
|
162
|
+
fee: str,
|
|
163
|
+
) -> None:
|
|
164
|
+
print("Adding secure lock cert to image registry")
|
|
165
|
+
nonce = self.w3.eth.getTransactionCount(self.acct.address)
|
|
166
|
+
unicorn_txn = self.image_registry.functions.addImage(
|
|
167
|
+
ipfs_hash,
|
|
168
|
+
cert_content,
|
|
169
|
+
"v3",
|
|
170
|
+
image_name,
|
|
171
|
+
docker_compose_hash,
|
|
172
|
+
enclave_name_securelock,
|
|
173
|
+
int(fee),
|
|
174
|
+
).buildTransaction(
|
|
175
|
+
{
|
|
176
|
+
"gas": GAS,
|
|
177
|
+
"chainId": CHAIN_ID,
|
|
178
|
+
"nonce": nonce,
|
|
179
|
+
"gasPrice": self.w3.toWei("1", "mwei") if GAS_PRICE == 1 else GAS_PRICE,
|
|
180
|
+
}
|
|
181
|
+
)
|
|
182
|
+
signed_txn = self.w3.eth.account.sign_transaction(
|
|
183
|
+
unicorn_txn, private_key=self.acct.key
|
|
184
|
+
)
|
|
185
|
+
self.w3.eth.sendRawTransaction(signed_txn.rawTransaction)
|
|
186
|
+
# self.transaction = unicorn_tx signed
|
|
187
|
+
hash = self.w3.toHex(self.w3.sha3(signed_txn.rawTransaction))
|
|
188
|
+
|
|
189
|
+
try:
|
|
190
|
+
receipt = self.w3.eth.waitForTransactionReceipt(hash)
|
|
191
|
+
except Exception as e:
|
|
192
|
+
print(f"An error occurred while sending transaction", e)
|
|
193
|
+
raise
|
|
194
|
+
|
|
195
|
+
print("transaction status: ", receipt.status)
|
|
196
|
+
print("transaction receipt: ", receipt)
|
|
197
|
+
if receipt.status == 1:
|
|
198
|
+
print("Adding secure lock transaction was successful!")
|
|
199
|
+
else:
|
|
200
|
+
print("Adding secure lock transaction was UNSUCCESSFUL!")
|
|
201
|
+
|
|
202
|
+
def validate_secure_lock_image_cert(self, ipfs_hash: str) -> None:
|
|
203
|
+
print("Validating secure lock cert to image registry")
|
|
204
|
+
nonce = self.w3.eth.getTransactionCount(self.acct.address)
|
|
205
|
+
unicorn_txn = self.image_registry.functions.validateImage(
|
|
206
|
+
ipfs_hash
|
|
207
|
+
).buildTransaction(
|
|
208
|
+
{
|
|
209
|
+
"gas": GAS,
|
|
210
|
+
"chainId": CHAIN_ID,
|
|
211
|
+
"nonce": nonce,
|
|
212
|
+
"gasPrice": self.w3.toWei("1", "mwei") if GAS_PRICE == 1 else GAS_PRICE,
|
|
213
|
+
}
|
|
214
|
+
)
|
|
215
|
+
signed_txn = self.w3.eth.account.sign_transaction(
|
|
216
|
+
unicorn_txn, private_key=self.acct.key
|
|
217
|
+
)
|
|
218
|
+
self.w3.eth.sendRawTransaction(signed_txn.rawTransaction)
|
|
219
|
+
# self.transaction = unicorn_tx signed
|
|
220
|
+
hash = self.w3.toHex(self.w3.sha3(signed_txn.rawTransaction))
|
|
221
|
+
|
|
222
|
+
try:
|
|
223
|
+
receipt = self.w3.eth.waitForTransactionReceipt(hash)
|
|
224
|
+
except Exception as e:
|
|
225
|
+
print(f"An error occurred while sending transaction", e)
|
|
226
|
+
raise
|
|
227
|
+
|
|
228
|
+
print("transaction status: ", receipt.status)
|
|
229
|
+
print("transaction receipt: ", receipt)
|
|
230
|
+
if receipt.status == 1:
|
|
231
|
+
print("Validating secure lock cert transaction was successful!")
|
|
232
|
+
else:
|
|
233
|
+
print("Validating secure lock cert transaction was UNSUCCESSFUL!")
|
|
234
|
+
|
|
235
|
+
def add_secure_lock_and_validate_image_cert(
|
|
236
|
+
self,
|
|
237
|
+
cert_content: str,
|
|
238
|
+
ipfs_hash: str,
|
|
239
|
+
image_name: str,
|
|
240
|
+
docker_compose_hash: str,
|
|
241
|
+
enclave_name_securelock: str,
|
|
242
|
+
fee: str,
|
|
243
|
+
) -> None:
|
|
244
|
+
self.add_secure_lock_image_cert(
|
|
245
|
+
cert_content,
|
|
246
|
+
ipfs_hash,
|
|
247
|
+
image_name,
|
|
248
|
+
docker_compose_hash,
|
|
249
|
+
enclave_name_securelock,
|
|
250
|
+
fee,
|
|
251
|
+
)
|
|
252
|
+
# self.validate_secure_lock_image_cert(ipfs_hash)
|
|
253
|
+
|
|
254
|
+
def get_trusted_zone_cert(self, image_ipfs_hash: str) -> None:
|
|
255
|
+
cert = self.image_registry.caller().getTrustedZoneImageCertPublicKey(
|
|
256
|
+
image_ipfs_hash
|
|
257
|
+
)
|
|
258
|
+
print(cert)
|
|
259
|
+
|
|
260
|
+
def get_secure_lock_cert(self, image_ipfs_hash: str) -> None:
|
|
261
|
+
cert = self.image_registry.caller().getImageCertPublicKey(image_ipfs_hash)
|
|
262
|
+
print(cert)
|
|
263
|
+
|
|
264
|
+
def get_image_details(self, image_ipfs_hash: str) -> list:
|
|
265
|
+
imageDetails = self.image_registry.caller().imageDetails(image_ipfs_hash)
|
|
266
|
+
return imageDetails
|
|
267
|
+
|
|
268
|
+
def get_latest_image_version_public_key(
|
|
269
|
+
self, image_name: str, image_version: str
|
|
270
|
+
) -> list:
|
|
271
|
+
imageVersionPublicKey = (
|
|
272
|
+
self.image_registry.caller().getLatestImageVersionPublicKey(
|
|
273
|
+
image_name, image_version
|
|
274
|
+
)
|
|
275
|
+
)
|
|
276
|
+
return imageVersionPublicKey
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
if __name__ == "__main__":
|
|
280
|
+
try:
|
|
281
|
+
network_name = sys.argv[1]
|
|
282
|
+
project_name = sys.argv[2]
|
|
283
|
+
version = sys.argv[3]
|
|
284
|
+
if network_name and project_name:
|
|
285
|
+
BLOCKCHAIN_NETWORK = network_name
|
|
286
|
+
except Exception as e:
|
|
287
|
+
print(e)
|
|
288
|
+
exit(0)
|
|
289
|
+
|
|
290
|
+
private_key = ""
|
|
291
|
+
try:
|
|
292
|
+
private_key = sys.argv[4]
|
|
293
|
+
except:
|
|
294
|
+
pass
|
|
295
|
+
set_vars(network_name)
|
|
296
|
+
|
|
297
|
+
image_registry = ImageRegistry()
|
|
298
|
+
try:
|
|
299
|
+
imageHash = image_registry.get_latest_image_version_public_key(
|
|
300
|
+
project_name, version
|
|
301
|
+
)[0]
|
|
302
|
+
imageOwner = image_registry.get_image_details(imageHash)[0]
|
|
303
|
+
|
|
304
|
+
if private_key:
|
|
305
|
+
if is_string_private_key(private_key) == "OK":
|
|
306
|
+
# check if the imageOwner is the same as the private key owner
|
|
307
|
+
_acct = Account.privateKeyToAccount(private_key)
|
|
308
|
+
# print("private key account address:" + _acct.address)
|
|
309
|
+
if imageOwner != _acct.address:
|
|
310
|
+
print(
|
|
311
|
+
f"!!! Image: '{project_name}' Version: '{version}' is owned by '{imageOwner}'.\nYou are not the account holder of the image.\nPlease change the project name and try again.\n"
|
|
312
|
+
)
|
|
313
|
+
exit(1)
|
|
314
|
+
|
|
315
|
+
# print(f"Image Owner: {imageOwner}")
|
|
316
|
+
if imageOwner:
|
|
317
|
+
print(
|
|
318
|
+
f"Image: '{project_name}' Version: '{version}' is owned by '{imageOwner}'.\nIf you are not the account holder, you will not be able to publish your project with the current name. Please change the project name and try again.\n"
|
|
319
|
+
)
|
|
320
|
+
exit(0)
|
|
321
|
+
except Exception as e:
|
|
322
|
+
# print(e)
|
|
323
|
+
pass
|
|
324
|
+
|
|
325
|
+
print(
|
|
326
|
+
f"Image: '{project_name}' Version: '{version}' is available on the {network_name} blockchain."
|
|
327
|
+
)
|