@cardano-sdk/e2e 0.20.0 → 0.21.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/CHANGELOG.md +30 -0
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/cjs/util/handle-util.d.ts +33 -0
- package/dist/cjs/util/handle-util.d.ts.map +1 -0
- package/dist/cjs/util/handle-util.js +108 -0
- package/dist/cjs/util/handle-util.js.map +1 -0
- package/dist/cjs/util/index.d.ts +1 -0
- package/dist/cjs/util/index.d.ts.map +1 -1
- package/dist/cjs/util/index.js +1 -0
- package/dist/cjs/util/index.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/util/handle-util.d.ts +33 -0
- package/dist/esm/util/handle-util.d.ts.map +1 -0
- package/dist/esm/util/handle-util.js +97 -0
- package/dist/esm/util/handle-util.js.map +1 -0
- package/dist/esm/util/index.d.ts +1 -0
- package/dist/esm/util/index.d.ts.map +1 -1
- package/dist/esm/util/index.js +1 -0
- package/dist/esm/util/index.js.map +1 -1
- package/local-network/scripts/mint-handles.sh +1 -1
- package/package.json +19 -19
- package/src/util/handle-util.ts +151 -0
- package/src/util/index.ts +1 -0
- package/test/k6/endpoints/stake-pool/search.test.js +60 -0
- package/test/long-running/delegation-rewards.test.ts +1 -0
- package/test/projection/single-tenant-utxo.test.ts +2 -1
- package/test/tsconfig.json +7 -2
- package/test/wallet/PersonalWallet/delegationDistribution.test.ts +14 -3
- package/test/wallet/PersonalWallet/handle.test.ts +45 -127
- package/test/wallet/PersonalWallet/nft.test.ts +0 -3
- package/test/wallet/PersonalWallet/phase2validation.test.ts +2 -2
- package/test/web-extension/extension/const.ts +2 -0
- package/test/web-extension/extension/stubWalletApi.ts +3 -3
- package/test/web-extension/extension/ui.html +3 -0
- package/test/web-extension/extension/ui.ts +22 -0
- package/test/web-extension/specs/dapp-cip95.spec.ts +1 -1
- package/test/web-extension/specs/wallet.spec.ts +15 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Cardano, Handle } from '@cardano-sdk/core';
|
|
2
|
+
import { ObservableWallet } from '@cardano-sdk/wallet';
|
|
3
|
+
import { KeyAgent, util as keyManagementUtil } from '@cardano-sdk/key-management';
|
|
4
|
+
export declare type HandleMetadata = {
|
|
5
|
+
[policyId: string]: {
|
|
6
|
+
[handleName: string]: {
|
|
7
|
+
augmentations: [];
|
|
8
|
+
core: {
|
|
9
|
+
handleEncoding: string;
|
|
10
|
+
og: number;
|
|
11
|
+
prefix: string;
|
|
12
|
+
termsofuse: string;
|
|
13
|
+
version: number;
|
|
14
|
+
};
|
|
15
|
+
description: string;
|
|
16
|
+
image: string;
|
|
17
|
+
name: string;
|
|
18
|
+
website: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export declare const createHandleMetadata: (handlePolicyId: string, handleNames: string[]) => HandleMetadata;
|
|
23
|
+
export declare const createHandlePolicy: (keyAgent: KeyAgent) => Promise<{
|
|
24
|
+
policyId: Cardano.PolicyId;
|
|
25
|
+
policyScript: Cardano.RequireSignatureScript;
|
|
26
|
+
policySigner: keyManagementUtil.KeyAgentTransactionSigner;
|
|
27
|
+
}>;
|
|
28
|
+
export declare const handleNames: Handle[];
|
|
29
|
+
export declare const getHandlePolicyId: (pathToSdkIpc: string) => Promise<Cardano.PolicyId>;
|
|
30
|
+
export declare const coinsRequiredByHandleMint = 10000000n;
|
|
31
|
+
export declare const mint: (wallet: ObservableWallet, keyAgent: KeyAgent, tokens: Cardano.TokenMap, txMetadatum: Cardano.Metadatum, datum?: Cardano.PlutusData) => Promise<void>;
|
|
32
|
+
export declare const mintCIP25andCIP68Handles: (wallet: ObservableWallet, keyAgent: KeyAgent, policyId: Cardano.PolicyId) => Promise<void>;
|
|
33
|
+
//# sourceMappingURL=handle-util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-util.d.ts","sourceRoot":"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|
|
1
|
+
import { Asset, Cardano, Serialization, metadatum, nativeScriptPolicyId, util } from '@cardano-sdk/core';
|
|
2
|
+
import { HexBlob } from '@cardano-sdk/util';
|
|
3
|
+
import { KeyRole, util as keyManagementUtil } from '@cardano-sdk/key-management';
|
|
4
|
+
import { firstValueFrom } from 'rxjs';
|
|
5
|
+
import { readFile } from 'fs/promises';
|
|
6
|
+
import { submitAndConfirm } from './util';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
const handleDatum = Serialization.PlutusData.fromCbor(HexBlob('d8799faa446e616d654a24706861726d6572733245696d6167655838697066733a2f2f7a646a37576d6f5a3656793564334b3675714253525a50527a5365625678624c326e315741514e4158336f4c6157655974496d65646961547970654a696d6167652f6a706567426f6700496f675f6e756d6265720046726172697479456261736963466c656e677468094a636861726163746572734f6c6574746572732c6e756d62657273516e756d657269635f6d6f64696669657273404776657273696f6e0101b34862675f696d6167655835697066733a2f2f516d59365869714272394a4e6e75677554527378336f63766b51656d4e4a356943524d6965383577717a39344a6f497066705f696d6167655835697066733a2f2f516d57676a58437856555357507931576d5556336a6f505031735a4d765a3731736f3671793643325a756b52424446706f7274616c404864657369676e65725838697066733a2f2f7a623272686b3278453154755757787448547a6f356774446945784136547276534b69596e6176704552334c66446b6f4b47736f6369616c73404676656e646f72404764656661756c74004e7374616e646172645f696d6167655838697066733a2f2f7a62327268696b435674535a7a4b756935336b76574c387974564374637a67457239424c6a466258423454585578684879536c6173745f7570646174655f61646472657373583901e80fd3030bfb17f25bfee50d2e71c9ece68292915698f955ea6645ea2b7be012268a95ebaefe5305164405df22ce4119a4a3549bbf1cda3d4c76616c6964617465645f6279581c4da965a049dfd15ed1ee19fba6e2974a0b79fc416dd1796a1f97f5e14a696d6167655f686173685820bcd58c0dceea97b717bcbe0edc40b2e65fc2329a4db9ce3716b47b90eb5167de537374616e646172645f696d6167655f686173685820b3d06b8604acc91729e4d10ff5f42da4137cbb6b943291f703eb97761673c9804b7376675f76657273696f6e46312e31352e304c6167726565645f7465726d7340546d6967726174655f7369675f726571756972656400446e7366770045747269616c00497066705f61737365745823e74862a09d17a9cb03174a6bd5fa305b8684475c4c36021591c606e0445030363831364862675f6173736574582c9bdf437b6831d46d92d0db80f19f1b702145e9fdcc43c6264f7a04dc001bc2805468652046726565204f6e65ff')).toCore();
|
|
9
|
+
export const createHandleMetadata = (handlePolicyId, handleNames) => {
|
|
10
|
+
const result = {};
|
|
11
|
+
for (const key of handleNames) {
|
|
12
|
+
result[key] = {
|
|
13
|
+
augmentations: [],
|
|
14
|
+
core: {
|
|
15
|
+
handleEncoding: 'utf-8',
|
|
16
|
+
og: 0,
|
|
17
|
+
prefix: '$',
|
|
18
|
+
termsofuse: 'https://cardanofoundation.org/en/terms-and-conditions/',
|
|
19
|
+
version: 0
|
|
20
|
+
},
|
|
21
|
+
description: 'The Handle Standard',
|
|
22
|
+
image: 'ipfs://some-hash',
|
|
23
|
+
name: `$${key}`,
|
|
24
|
+
website: 'https://cardano.org/'
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return { [handlePolicyId]: result };
|
|
28
|
+
};
|
|
29
|
+
export const createHandlePolicy = async (keyAgent) => {
|
|
30
|
+
const derivationPath = {
|
|
31
|
+
index: 0,
|
|
32
|
+
role: KeyRole.External
|
|
33
|
+
};
|
|
34
|
+
const pubKey = await keyAgent.derivePublicKey(derivationPath);
|
|
35
|
+
const keyHash = await keyAgent.bip32Ed25519.getPubKeyHash(pubKey);
|
|
36
|
+
const policySigner = new keyManagementUtil.KeyAgentTransactionSigner(keyAgent, derivationPath);
|
|
37
|
+
const policyScript = {
|
|
38
|
+
__type: Cardano.ScriptType.Native,
|
|
39
|
+
keyHash,
|
|
40
|
+
kind: Cardano.NativeScriptKind.RequireSignature
|
|
41
|
+
};
|
|
42
|
+
const policyId = nativeScriptPolicyId(policyScript);
|
|
43
|
+
return { policyId, policyScript, policySigner };
|
|
44
|
+
};
|
|
45
|
+
export const handleNames = ['handle1', 'handle2'];
|
|
46
|
+
export const getHandlePolicyId = async (pathToSdkIpc) => {
|
|
47
|
+
const handleProviderPolicyId = (await readFile(path.join(pathToSdkIpc, 'handle_policy_ids')))
|
|
48
|
+
.toString('utf8')
|
|
49
|
+
.replace(/\s/g, '');
|
|
50
|
+
return Cardano.PolicyId(handleProviderPolicyId);
|
|
51
|
+
};
|
|
52
|
+
export const coinsRequiredByHandleMint = 10000000n;
|
|
53
|
+
export const mint = async (wallet, keyAgent, tokens, txMetadatum, datum) => {
|
|
54
|
+
const [{ address }] = await firstValueFrom(wallet.addresses$);
|
|
55
|
+
const { policyScript, policySigner } = await createHandlePolicy(keyAgent);
|
|
56
|
+
const auxiliaryData = {
|
|
57
|
+
blob: new Map([[721n, txMetadatum]])
|
|
58
|
+
};
|
|
59
|
+
const txProps = {
|
|
60
|
+
auxiliaryData,
|
|
61
|
+
mint: tokens,
|
|
62
|
+
outputs: new Set([
|
|
63
|
+
{
|
|
64
|
+
address,
|
|
65
|
+
datum,
|
|
66
|
+
value: {
|
|
67
|
+
assets: tokens,
|
|
68
|
+
coins: coinsRequiredByHandleMint
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
]),
|
|
72
|
+
witness: { extraSigners: [policySigner], scripts: [policyScript] }
|
|
73
|
+
};
|
|
74
|
+
const unsignedTx = await wallet.initializeTx(txProps);
|
|
75
|
+
const finalizeProps = {
|
|
76
|
+
auxiliaryData,
|
|
77
|
+
tx: unsignedTx,
|
|
78
|
+
witness: { extraSigners: [policySigner], scripts: [policyScript] }
|
|
79
|
+
};
|
|
80
|
+
const signedTx = await wallet.finalizeTx(finalizeProps);
|
|
81
|
+
await submitAndConfirm(wallet, signedTx);
|
|
82
|
+
};
|
|
83
|
+
export const mintCIP25andCIP68Handles = async (wallet, keyAgent, policyId) => {
|
|
84
|
+
const [cip25handle, cip68handle] = handleNames;
|
|
85
|
+
const decodedCIP68HandleAssetName = Cardano.AssetName(util.utf8ToHex(cip68handle));
|
|
86
|
+
const cip68UserTokenAssetId = Cardano.AssetId.fromParts(policyId, Asset.AssetNameLabel.encode(decodedCIP68HandleAssetName, Asset.AssetNameLabelNum.UserNFT));
|
|
87
|
+
const cip68ReferenceTokenAssetId = Cardano.AssetId.fromParts(policyId, Asset.AssetNameLabel.encode(decodedCIP68HandleAssetName, Asset.AssetNameLabelNum.ReferenceNFT));
|
|
88
|
+
const cip25AssetId = Cardano.AssetId.fromParts(policyId, Cardano.AssetName(util.utf8ToHex(cip25handle)));
|
|
89
|
+
const tokens = new Map([
|
|
90
|
+
[cip25AssetId, 1n],
|
|
91
|
+
[cip68ReferenceTokenAssetId, 1n],
|
|
92
|
+
[cip68UserTokenAssetId, 1n]
|
|
93
|
+
]);
|
|
94
|
+
const txMetadatum = metadatum.jsonToMetadatum(createHandleMetadata(policyId, [cip25handle]));
|
|
95
|
+
await mint(wallet, keyAgent, tokens, txMetadatum, handleDatum);
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=handle-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-util.js","sourceRoot":"","sources":["../../../src/util/handle-util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAU,aAAa,EAAE,SAAS,EAAE,oBAAoB,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEjH,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAY,OAAO,EAAE,IAAI,IAAI,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,WAAW,GAAG,aAAa,CAAC,UAAU,CAAC,QAAQ,CACnD,OAAO,CAEL,4vDAA4vD,CAC7vD,CACF,CAAC,M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GAAG,CAAC;QACrB,CAAC,YAAY,EAAE,EAAE,CAAC;QAClB,CAAC,0BAA0B,EAAE,EAAE,CAAC;QAChC,CAAC,qBAAqB,EAAE,EAAE,CAAC;KAC5B,CAAC,CAAC;IACH,MAAM,WAAW,GAAG,SAAS,CAAC,eAAe,CAAC,oBAAoB,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAC7F,MAAM,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AACjE,CAAC,CAAC"}
|
package/dist/esm/util/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC"}
|
package/dist/esm/util/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC"}
|
|
@@ -39,7 +39,7 @@ cat >network-files/utxo-keys/handles-metadata.json <<EOL
|
|
|
39
39
|
{"${policyid}":
|
|
40
40
|
{
|
|
41
41
|
"${handleNames[0]}": {"core": {"og": 0, "prefix": "$", "version": 0, "termsofuse": "https://cardanofoundation.org/en/terms-and-conditions/", "handleEncoding": "utf-8"}, "name": "${handleNames[0]}", "image": "ipfs://some-hash", "website": "https://cardano.org/", "description": "The Handle Standard", "augmentations": []},
|
|
42
|
-
"${handleNames[1]}": {"core": {"og": 0, "prefix": "$", "version": 0, "termsofuse": "https://cardanofoundation.org/en/terms-and-conditions/", "handleEncoding": "utf-8"}, "name": "${handleNames[1]}", "image": "ipfs://some-hash", "website": "https://cardano.org/", "description": "The Handle Standard", "augmentations": []},
|
|
42
|
+
"${handleNames[1]}": {"core": {"og": 0, "prefix": "$", "version": 0, "termsofuse": "https://cardanofoundation.org/en/terms-and-conditions/", "handleEncoding": "utf-8"}, "name": "${handleNames[1]}", "image": "ipfs://some-hash", "mediaType": "image/jpeg", "files": [{"src": "ipfs://Qmb78QQ4RXxKQrteRn4X3WaMXXfmi2BU2dLjfWxuJoF2N5", "name": "some name", "mediaType": "video/mp4"}, {"src": ["ipfs://Qmb78QQ4RXxKQrteRn4X3WaMXXfmi2", "BU2dLjfWxuJoF2Ny"], "name": "some name", "mediaType": "audio/mpeg"}], "website": "https://cardano.org/", "description": "The Handle Standard", "augmentations": []},
|
|
43
43
|
"${handleNames[2]}": {"core": {"og": 0, "prefix": "$", "version": 0, "termsofuse": "https://cardanofoundation.org/en/terms-and-conditions/", "handleEncoding": "utf-8"}, "name": "${handleNames[2]}", "image": "ipfs://some-hash", "website": "https://cardano.org/", "description": "The Handle Standard", "augmentations": []},
|
|
44
44
|
"${handleNames[3]}": {"core": {"og": 0, "prefix": "$", "version": 0, "termsofuse": "https://cardanofoundation.org/en/terms-and-conditions/", "handleEncoding": "utf-8"}, "name": "${handleNames[3]}", "image": "ipfs://some-hash", "website": "https://cardano.org/", "description": "The Handle Standard", "augmentations": []}
|
|
45
45
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cardano-sdk/e2e",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "End to end tests for the cardano-js-sdk packages.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=16.20.1"
|
|
@@ -81,19 +81,19 @@
|
|
|
81
81
|
"dependencies": {
|
|
82
82
|
"@cardano-foundation/ledgerjs-hw-app-cardano": "^6.0.0",
|
|
83
83
|
"@cardano-ogmios/client": "5.6.0",
|
|
84
|
-
"@cardano-sdk/cardano-services": "~0.
|
|
85
|
-
"@cardano-sdk/cardano-services-client": "~0.
|
|
86
|
-
"@cardano-sdk/core": "~0.
|
|
87
|
-
"@cardano-sdk/crypto": "~0.1.
|
|
88
|
-
"@cardano-sdk/hardware-ledger": "~0.
|
|
89
|
-
"@cardano-sdk/input-selection": "~0.
|
|
90
|
-
"@cardano-sdk/key-management": "~0.
|
|
91
|
-
"@cardano-sdk/ogmios": "~0.
|
|
92
|
-
"@cardano-sdk/tx-construction": "~0.
|
|
93
|
-
"@cardano-sdk/util": "~0.14.
|
|
94
|
-
"@cardano-sdk/util-dev": "~0.
|
|
95
|
-
"@cardano-sdk/util-rxjs": "~0.5.
|
|
96
|
-
"@cardano-sdk/wallet": "~0.
|
|
84
|
+
"@cardano-sdk/cardano-services": "~0.19.0",
|
|
85
|
+
"@cardano-sdk/cardano-services-client": "~0.14.0",
|
|
86
|
+
"@cardano-sdk/core": "~0.20.0",
|
|
87
|
+
"@cardano-sdk/crypto": "~0.1.14",
|
|
88
|
+
"@cardano-sdk/hardware-ledger": "~0.4.0",
|
|
89
|
+
"@cardano-sdk/input-selection": "~0.12.0",
|
|
90
|
+
"@cardano-sdk/key-management": "~0.11.0",
|
|
91
|
+
"@cardano-sdk/ogmios": "~0.13.0",
|
|
92
|
+
"@cardano-sdk/tx-construction": "~0.12.0",
|
|
93
|
+
"@cardano-sdk/util": "~0.14.1",
|
|
94
|
+
"@cardano-sdk/util-dev": "~0.16.0",
|
|
95
|
+
"@cardano-sdk/util-rxjs": "~0.5.11",
|
|
96
|
+
"@cardano-sdk/wallet": "~0.22.0",
|
|
97
97
|
"@vespaiach/axios-fetch-adapter": "^0.3.0",
|
|
98
98
|
"axios": "^0.27.2",
|
|
99
99
|
"bunyan": "^1.8.15",
|
|
@@ -122,10 +122,10 @@
|
|
|
122
122
|
"@babel/core": "^7.18.2",
|
|
123
123
|
"@babel/preset-env": "^7.18.2",
|
|
124
124
|
"@babel/preset-typescript": "^7.17.12",
|
|
125
|
-
"@cardano-sdk/dapp-connector": "~0.
|
|
126
|
-
"@cardano-sdk/projection": "~0.
|
|
127
|
-
"@cardano-sdk/projection-typeorm": "~0.
|
|
128
|
-
"@cardano-sdk/web-extension": "~0.
|
|
125
|
+
"@cardano-sdk/dapp-connector": "~0.10.0",
|
|
126
|
+
"@cardano-sdk/projection": "~0.8.0",
|
|
127
|
+
"@cardano-sdk/projection-typeorm": "~0.5.0",
|
|
128
|
+
"@cardano-sdk/web-extension": "~0.15.0",
|
|
129
129
|
"@dcspark/cardano-multiplatform-lib-browser": "^3.1.1",
|
|
130
130
|
"@emurgo/cardano-message-signing-asmjs": "^1.0.1",
|
|
131
131
|
"@types/bunyan": "^1.8.8",
|
|
@@ -178,5 +178,5 @@
|
|
|
178
178
|
"webpack-cli": "^4.9.2",
|
|
179
179
|
"webpack-merge": "^5.8.0"
|
|
180
180
|
},
|
|
181
|
-
"gitHead": "
|
|
181
|
+
"gitHead": "88248ef21f11b3f38564b6cddd642c1c91aec66b"
|
|
182
182
|
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { Asset, Cardano, Handle, Serialization, metadatum, nativeScriptPolicyId, util } from '@cardano-sdk/core';
|
|
2
|
+
import { FinalizeTxProps, ObservableWallet } from '@cardano-sdk/wallet';
|
|
3
|
+
import { HexBlob } from '@cardano-sdk/util';
|
|
4
|
+
import { InitializeTxProps } from '@cardano-sdk/tx-construction';
|
|
5
|
+
import { KeyAgent, KeyRole, util as keyManagementUtil } from '@cardano-sdk/key-management';
|
|
6
|
+
import { firstValueFrom } from 'rxjs';
|
|
7
|
+
import { readFile } from 'fs/promises';
|
|
8
|
+
import { submitAndConfirm } from './util';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
|
|
11
|
+
const handleDatum = Serialization.PlutusData.fromCbor(
|
|
12
|
+
HexBlob(
|
|
13
|
+
// https://cexplorer.io/datum/8b828de43929ce9a10ac218cc690360f69eb50b42e6a3a2f92d05ea8ca6bf288
|
|
14
|
+
'd8799faa446e616d654a24706861726d6572733245696d6167655838697066733a2f2f7a646a37576d6f5a3656793564334b3675714253525a50527a5365625678624c326e315741514e4158336f4c6157655974496d65646961547970654a696d6167652f6a706567426f6700496f675f6e756d6265720046726172697479456261736963466c656e677468094a636861726163746572734f6c6574746572732c6e756d62657273516e756d657269635f6d6f64696669657273404776657273696f6e0101b34862675f696d6167655835697066733a2f2f516d59365869714272394a4e6e75677554527378336f63766b51656d4e4a356943524d6965383577717a39344a6f497066705f696d6167655835697066733a2f2f516d57676a58437856555357507931576d5556336a6f505031735a4d765a3731736f3671793643325a756b52424446706f7274616c404864657369676e65725838697066733a2f2f7a623272686b3278453154755757787448547a6f356774446945784136547276534b69596e6176704552334c66446b6f4b47736f6369616c73404676656e646f72404764656661756c74004e7374616e646172645f696d6167655838697066733a2f2f7a62327268696b435674535a7a4b756935336b76574c387974564374637a67457239424c6a466258423454585578684879536c6173745f7570646174655f61646472657373583901e80fd3030bfb17f25bfee50d2e71c9ece68292915698f955ea6645ea2b7be012268a95ebaefe5305164405df22ce4119a4a3549bbf1cda3d4c76616c6964617465645f6279581c4da965a049dfd15ed1ee19fba6e2974a0b79fc416dd1796a1f97f5e14a696d6167655f686173685820bcd58c0dceea97b717bcbe0edc40b2e65fc2329a4db9ce3716b47b90eb5167de537374616e646172645f696d6167655f686173685820b3d06b8604acc91729e4d10ff5f42da4137cbb6b943291f703eb97761673c9804b7376675f76657273696f6e46312e31352e304c6167726565645f7465726d7340546d6967726174655f7369675f726571756972656400446e7366770045747269616c00497066705f61737365745823e74862a09d17a9cb03174a6bd5fa305b8684475c4c36021591c606e0445030363831364862675f6173736574582c9bdf437b6831d46d92d0db80f19f1b702145e9fdcc43c6264f7a04dc001bc2805468652046726565204f6e65ff'
|
|
15
|
+
)
|
|
16
|
+
).toCore();
|
|
17
|
+
|
|
18
|
+
export type HandleMetadata = {
|
|
19
|
+
[policyId: string]: {
|
|
20
|
+
[handleName: string]: {
|
|
21
|
+
augmentations: [];
|
|
22
|
+
core: {
|
|
23
|
+
handleEncoding: string;
|
|
24
|
+
og: number;
|
|
25
|
+
prefix: string;
|
|
26
|
+
termsofuse: string;
|
|
27
|
+
version: number;
|
|
28
|
+
};
|
|
29
|
+
description: string;
|
|
30
|
+
image: string;
|
|
31
|
+
name: string;
|
|
32
|
+
website: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const createHandleMetadata = (handlePolicyId: string, handleNames: string[]): HandleMetadata => {
|
|
38
|
+
const result: HandleMetadata[0] = {};
|
|
39
|
+
for (const key of handleNames) {
|
|
40
|
+
result[key] = {
|
|
41
|
+
augmentations: [],
|
|
42
|
+
core: {
|
|
43
|
+
handleEncoding: 'utf-8',
|
|
44
|
+
og: 0,
|
|
45
|
+
prefix: '$',
|
|
46
|
+
termsofuse: 'https://cardanofoundation.org/en/terms-and-conditions/',
|
|
47
|
+
version: 0
|
|
48
|
+
},
|
|
49
|
+
description: 'The Handle Standard',
|
|
50
|
+
image: 'ipfs://some-hash',
|
|
51
|
+
name: `$${key}`,
|
|
52
|
+
website: 'https://cardano.org/'
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return { [handlePolicyId]: result };
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const createHandlePolicy = async (keyAgent: KeyAgent) => {
|
|
59
|
+
const derivationPath = {
|
|
60
|
+
index: 0,
|
|
61
|
+
role: KeyRole.External
|
|
62
|
+
};
|
|
63
|
+
const pubKey = await keyAgent.derivePublicKey(derivationPath);
|
|
64
|
+
const keyHash = await keyAgent.bip32Ed25519.getPubKeyHash(pubKey);
|
|
65
|
+
const policySigner = new keyManagementUtil.KeyAgentTransactionSigner(keyAgent, derivationPath);
|
|
66
|
+
const policyScript: Cardano.NativeScript = {
|
|
67
|
+
__type: Cardano.ScriptType.Native,
|
|
68
|
+
keyHash,
|
|
69
|
+
kind: Cardano.NativeScriptKind.RequireSignature
|
|
70
|
+
};
|
|
71
|
+
const policyId = nativeScriptPolicyId(policyScript);
|
|
72
|
+
return { policyId, policyScript, policySigner };
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const handleNames: Handle[] = ['handle1', 'handle2'];
|
|
76
|
+
|
|
77
|
+
export const getHandlePolicyId = async (pathToSdkIpc: string): Promise<Cardano.PolicyId> => {
|
|
78
|
+
const handleProviderPolicyId = (await readFile(path.join(pathToSdkIpc, 'handle_policy_ids')))
|
|
79
|
+
.toString('utf8')
|
|
80
|
+
.replace(/\s/g, '');
|
|
81
|
+
return Cardano.PolicyId(handleProviderPolicyId);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const coinsRequiredByHandleMint = 10_000_000n;
|
|
85
|
+
|
|
86
|
+
export const mint = async (
|
|
87
|
+
wallet: ObservableWallet,
|
|
88
|
+
keyAgent: KeyAgent,
|
|
89
|
+
tokens: Cardano.TokenMap,
|
|
90
|
+
txMetadatum: Cardano.Metadatum,
|
|
91
|
+
datum?: Cardano.PlutusData
|
|
92
|
+
) => {
|
|
93
|
+
const [{ address }] = await firstValueFrom(wallet.addresses$);
|
|
94
|
+
const { policyScript, policySigner } = await createHandlePolicy(keyAgent);
|
|
95
|
+
|
|
96
|
+
const auxiliaryData = {
|
|
97
|
+
blob: new Map([[721n, txMetadatum]])
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const txProps: InitializeTxProps = {
|
|
101
|
+
auxiliaryData,
|
|
102
|
+
mint: tokens,
|
|
103
|
+
outputs: new Set([
|
|
104
|
+
{
|
|
105
|
+
address,
|
|
106
|
+
datum,
|
|
107
|
+
value: {
|
|
108
|
+
assets: tokens,
|
|
109
|
+
coins: coinsRequiredByHandleMint
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
]),
|
|
113
|
+
witness: { extraSigners: [policySigner], scripts: [policyScript] }
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const unsignedTx = await wallet.initializeTx(txProps);
|
|
117
|
+
|
|
118
|
+
const finalizeProps: FinalizeTxProps = {
|
|
119
|
+
auxiliaryData,
|
|
120
|
+
tx: unsignedTx,
|
|
121
|
+
witness: { extraSigners: [policySigner], scripts: [policyScript] }
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const signedTx = await wallet.finalizeTx(finalizeProps);
|
|
125
|
+
await submitAndConfirm(wallet, signedTx);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export const mintCIP25andCIP68Handles = async (
|
|
129
|
+
wallet: ObservableWallet,
|
|
130
|
+
keyAgent: KeyAgent,
|
|
131
|
+
policyId: Cardano.PolicyId
|
|
132
|
+
) => {
|
|
133
|
+
const [cip25handle, cip68handle] = handleNames;
|
|
134
|
+
const decodedCIP68HandleAssetName = Cardano.AssetName(util.utf8ToHex(cip68handle));
|
|
135
|
+
const cip68UserTokenAssetId = Cardano.AssetId.fromParts(
|
|
136
|
+
policyId,
|
|
137
|
+
Asset.AssetNameLabel.encode(decodedCIP68HandleAssetName, Asset.AssetNameLabelNum.UserNFT)
|
|
138
|
+
);
|
|
139
|
+
const cip68ReferenceTokenAssetId = Cardano.AssetId.fromParts(
|
|
140
|
+
policyId,
|
|
141
|
+
Asset.AssetNameLabel.encode(decodedCIP68HandleAssetName, Asset.AssetNameLabelNum.ReferenceNFT)
|
|
142
|
+
);
|
|
143
|
+
const cip25AssetId = Cardano.AssetId.fromParts(policyId, Cardano.AssetName(util.utf8ToHex(cip25handle)));
|
|
144
|
+
const tokens = new Map([
|
|
145
|
+
[cip25AssetId, 1n],
|
|
146
|
+
[cip68ReferenceTokenAssetId, 1n],
|
|
147
|
+
[cip68UserTokenAssetId, 1n]
|
|
148
|
+
]);
|
|
149
|
+
const txMetadatum = metadatum.jsonToMetadatum(createHandleMetadata(policyId, [cip25handle]));
|
|
150
|
+
await mint(wallet, keyAgent, tokens, txMetadatum, handleDatum);
|
|
151
|
+
};
|
package/src/util/index.ts
CHANGED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { check } from 'k6';
|
|
2
|
+
import http from 'k6/http';
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line no-undef
|
|
5
|
+
const STAKE_POOL_PROVIDER_URL = __ENV.PROVIDER_SERVER_URL;
|
|
6
|
+
const MAX_STAKE_POOLS = 500;
|
|
7
|
+
export const options = {
|
|
8
|
+
thresholds: {
|
|
9
|
+
http_req_duration: ['p(95)<500'],
|
|
10
|
+
http_req_failed: ['rate<0.01']
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const setup = () => {
|
|
15
|
+
const stakePools = [];
|
|
16
|
+
let idx = 0;
|
|
17
|
+
const limit = 25;
|
|
18
|
+
|
|
19
|
+
// Get the list of stake pools
|
|
20
|
+
while (stakePools.length < MAX_STAKE_POOLS) {
|
|
21
|
+
const searchResponse = http.post(
|
|
22
|
+
`${STAKE_POOL_PROVIDER_URL}/stake-pool/search`,
|
|
23
|
+
JSON.stringify({
|
|
24
|
+
pagination: {
|
|
25
|
+
limit,
|
|
26
|
+
startAt: idx * limit
|
|
27
|
+
}
|
|
28
|
+
}),
|
|
29
|
+
{
|
|
30
|
+
headers: {
|
|
31
|
+
'Content-Type': 'application/json'
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
idx++;
|
|
36
|
+
check(searchResponse, {
|
|
37
|
+
'Initial query successfull': (r) => r.status === 200
|
|
38
|
+
});
|
|
39
|
+
const parsedPageResults = JSON.parse(searchResponse.body.toString()).pageResults;
|
|
40
|
+
stakePools.push(...parsedPageResults);
|
|
41
|
+
if (parsedPageResults.length < 25) break;
|
|
42
|
+
}
|
|
43
|
+
return { stakePools };
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export default function (data) {
|
|
47
|
+
const randomIndex = Math.floor(Math.random() * data.stakePools.length);
|
|
48
|
+
// Select random stake pool from the list to query by id
|
|
49
|
+
const stakePool = data.stakePools[randomIndex];
|
|
50
|
+
const requestBody = {
|
|
51
|
+
filters: {
|
|
52
|
+
identifier: { values: [{ id: stakePool.id }] },
|
|
53
|
+
pledgeMet: true
|
|
54
|
+
},
|
|
55
|
+
pagination: { limit: 2, startAt: 0 }
|
|
56
|
+
};
|
|
57
|
+
return http.post(`${STAKE_POOL_PROVIDER_URL}/stake-pool/search`, JSON.stringify(requestBody), {
|
|
58
|
+
headers: { 'Content-Type': 'application/json' }
|
|
59
|
+
});
|
|
60
|
+
}
|
|
@@ -21,6 +21,7 @@ const submitDelegationTx = async (wallet: PersonalWallet, pools: Cardano.PoolId[
|
|
|
21
21
|
const { tx: signedTx } = await wallet
|
|
22
22
|
.createTxBuilder()
|
|
23
23
|
.delegatePortfolio({
|
|
24
|
+
name: 'Test Portfolio',
|
|
24
25
|
pools: pools.map((poolId) => ({ id: Cardano.PoolIdHex(Cardano.PoolId.toKeyHash(poolId)), weight: 1 }))
|
|
25
26
|
})
|
|
26
27
|
.build()
|
package/test/tsconfig.json
CHANGED
|
@@ -3,8 +3,13 @@
|
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"baseUrl": "."
|
|
5
5
|
},
|
|
6
|
-
"exclude": [
|
|
7
|
-
|
|
6
|
+
"exclude": [
|
|
7
|
+
"./web-extension"
|
|
8
|
+
],
|
|
9
|
+
"include": [
|
|
10
|
+
"./**/*.ts",
|
|
11
|
+
"../src/util/handle-util.ts"
|
|
12
|
+
],
|
|
8
13
|
"references": [
|
|
9
14
|
{
|
|
10
15
|
"path": "../src"
|
|
@@ -95,14 +95,15 @@ const delegateToMultiplePools = async (
|
|
|
95
95
|
weights = Array.from({ length: POOLS_COUNT }).map(() => 1)
|
|
96
96
|
) => {
|
|
97
97
|
const poolIds = await getPoolIds(wallet);
|
|
98
|
-
const portfolio:
|
|
98
|
+
const portfolio: Cardano.Cip17DelegationPortfolio = {
|
|
99
|
+
name: 'Test Portfolio',
|
|
99
100
|
pools: poolIds.map(({ hexId: id }, idx) => ({ id, weight: weights[idx] }))
|
|
100
101
|
};
|
|
101
102
|
logger.debug('Delegating portfolio', portfolio);
|
|
102
103
|
|
|
103
104
|
const { tx } = await wallet.createTxBuilder().delegatePortfolio(portfolio).build().sign();
|
|
104
105
|
await submitAndConfirm(wallet, tx);
|
|
105
|
-
return poolIds;
|
|
106
|
+
return { poolIds, portfolio };
|
|
106
107
|
};
|
|
107
108
|
|
|
108
109
|
const delegateAllToSinglePool = async (wallet: PersonalWallet): Promise<void> => {
|
|
@@ -138,10 +139,12 @@ describe('PersonalWallet/delegationDistribution', () => {
|
|
|
138
139
|
|
|
139
140
|
// No stake distribution initially
|
|
140
141
|
const delegationDistribution = await firstValueFrom(wallet.delegation.distribution$);
|
|
142
|
+
const delegationPortfolio = await firstValueFrom(wallet.delegation.portfolio$);
|
|
141
143
|
logger.info('Empty delegation distribution initially');
|
|
142
144
|
expect(delegationDistribution).toEqual(new Map());
|
|
145
|
+
expect(delegationPortfolio).toEqual(null);
|
|
143
146
|
|
|
144
|
-
const poolIds = await delegateToMultiplePools(wallet);
|
|
147
|
+
const { poolIds, portfolio } = await delegateToMultiplePools(wallet);
|
|
145
148
|
const walletAddresses = await firstValueFromTimed(wallet.addresses$);
|
|
146
149
|
const rewardAccounts = await firstValueFrom(wallet.delegation.rewardAccounts$);
|
|
147
150
|
|
|
@@ -173,11 +176,13 @@ describe('PersonalWallet/delegationDistribution', () => {
|
|
|
173
176
|
stake: perAddrBalance[index]
|
|
174
177
|
}));
|
|
175
178
|
const actualDelegationDistribution = await firstValueFrom(wallet.delegation.distribution$);
|
|
179
|
+
const actualPortfolio = await firstValueFrom(wallet.delegation.portfolio$);
|
|
176
180
|
|
|
177
181
|
logger.info('Funds were distributed evenly across the addresses.');
|
|
178
182
|
logger.info(distributionMessage, actualDelegationDistribution);
|
|
179
183
|
|
|
180
184
|
expect([...actualDelegationDistribution.values()]).toEqual(expectedDelegationDistribution);
|
|
185
|
+
expect(portfolio).toEqual(actualPortfolio);
|
|
181
186
|
|
|
182
187
|
// Delegate so that last address has all funds
|
|
183
188
|
await delegateToMultiplePools(
|
|
@@ -229,6 +234,7 @@ describe('PersonalWallet/delegationDistribution', () => {
|
|
|
229
234
|
)
|
|
230
235
|
)
|
|
231
236
|
);
|
|
237
|
+
|
|
232
238
|
expect(simplifiedDelegationDistribution).toEqual([
|
|
233
239
|
{
|
|
234
240
|
id: poolIds[0].id,
|
|
@@ -237,5 +243,10 @@ describe('PersonalWallet/delegationDistribution', () => {
|
|
|
237
243
|
rewardAccounts: rewardAccounts.map(({ address }) => address)
|
|
238
244
|
}
|
|
239
245
|
]);
|
|
246
|
+
|
|
247
|
+
// The simplified portfolio transaction doesn't send a portfolio but rather simply delegates all funds to one pool manually.
|
|
248
|
+
// This emulates the case where a user syncs its seeds phrases into another wallet and delegates to a single pool (without attaching metadata),
|
|
249
|
+
// this action undoes the portfolio, we should get null here.
|
|
250
|
+
expect(await firstValueFrom(wallet.delegation.portfolio$)).toBe(null);
|
|
240
251
|
});
|
|
241
252
|
});
|