-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcover-sdk.js
105 lines (88 loc) · 3.02 KB
/
cover-sdk.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import fs from "fs";
import {getPublicKey, sign, Cover} from "@psychedelic/cover";
import {Ed25519KeyIdentity} from "@dfinity/identity";
import {Principal} from "@dfinity/principal";
const pem = fs
.readFileSync(process.env.PEM_PATH)
.toString()
.replace("-----BEGIN PRIVATE KEY-----", "")
.replace("-----END PRIVATE KEY-----", "")
.replace("\n", "")
.trim();
const raw = Buffer.from(pem, "base64")
.toString("hex")
.replace("3053020101300506032b657004220420", "")
.replace("a123032100", "");
const key = new Uint8Array(Buffer.from(raw, "hex"));
const identity = Ed25519KeyIdentity.fromSecretKey(key);
// get public key
const publicKey = getPublicKey(identity);
console.log("publicKey", publicKey);
// sign a signature
const timestamp = new Date().getTime();
console.log("timestamp", timestamp);
const signature = await sign(identity, timestamp);
console.log("signature", signature);
// =========================================================================================================
// EXAMPLE
// =========================================================================================================
const cover = new Cover(identity, {isDevelopment: true});
await cover.deleteMyBuildConfig(Principal.from("3x7en-uqaaa-aaaai-abgca-cai"));
await cover.saveBuildConfig({
canisterId: "3x7en-uqaaa-aaaai-abgca-cai",
dfxVersion: "0.11.2",
delegateCanisterId: "",
canisterName: "cover_test",
commitHash: "1423bbf5596263d75fb5414fea45237f9b6ed4f2",
repoUrl: "psychedelic/cover",
rustVersion: "1.63.0",
optimizeCount: 0,
repoAccessToken: "",
});
const buildConfigs = await cover.getMyBuildConfigs(
Principal.from("3x7en-uqaaa-aaaai-abgca-cai")
);
console.log("buildConfigs", buildConfigs);
const buildConfig = await cover.getMyBuildConfigById(
Principal.from("3x7en-uqaaa-aaaai-abgca-cai")
);
console.log("buildConfig", buildConfig);
const anonymousCoverMetadata = await Cover.anonymousCoverMetadata(
Principal.from("3x7en-uqaaa-aaaai-abgca-cai")
);
console.log("anonymousCoverMetadata", anonymousCoverMetadata);
const coverMetadata = await cover.coverMetadata(
Principal.from("3x7en-uqaaa-aaaai-abgca-cai")
);
console.log("coverMetadata", coverMetadata);
// ========================================================================================================
// BUILD
// ========================================================================================================
cover
.buildWithConfig({
canisterId: "3x7en-uqaaa-aaaai-abgca-cai",
repoAccessToken: "",
})
.catch(console.error);
Cover.buildWithCoverMetadata(
{
canisterId: "3x7en-uqaaa-aaaai-abgca-cai",
repoAccessToken: "",
},
{
isDevelopment: true,
}
).catch(console.error);
cover
.build({
canisterId: "3x7en-uqaaa-aaaai-abgca-cai",
dfxVersion: "0.11.2",
delegateCanisterId: "",
canisterName: "cover_test",
commitHash: "1423bbf5596263d75fb5414fea45237f9b6ed4f2",
repoUrl: "psychedelic/cover",
rustVersion: "1.63.0",
optimizeCount: 0,
repoAccessToken: "",
})
.catch(console.error);