@trustvc/trustvc 1.5.5 → 1.6.0-alpha.2
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/dist/cjs/core/endorsement-chain/useEndorsementChain.js +5 -6
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/token-registry-functions/index.js +40 -0
- package/dist/cjs/token-registry-functions/mint.js +86 -0
- package/dist/cjs/token-registry-functions/ownerOf.js +45 -0
- package/dist/cjs/token-registry-functions/rejectTransfers.js +123 -0
- package/dist/cjs/token-registry-functions/returnToken.js +204 -0
- package/dist/cjs/token-registry-functions/transfer.js +305 -0
- package/dist/cjs/token-registry-functions/types.js +2 -0
- package/dist/cjs/token-registry-functions/utils.js +37 -0
- package/dist/esm/core/endorsement-chain/useEndorsementChain.js +5 -7
- package/dist/esm/index.js +1 -0
- package/dist/esm/token-registry-functions/index.js +5 -0
- package/dist/esm/token-registry-functions/mint.js +84 -0
- package/dist/esm/token-registry-functions/ownerOf.js +43 -0
- package/dist/esm/token-registry-functions/rejectTransfers.js +119 -0
- package/dist/esm/token-registry-functions/returnToken.js +200 -0
- package/dist/esm/token-registry-functions/transfer.js +300 -0
- package/dist/esm/token-registry-functions/types.js +1 -0
- package/dist/esm/token-registry-functions/utils.js +33 -0
- package/dist/types/core/endorsement-chain/index.d.ts +1 -1
- package/dist/types/core/endorsement-chain/useEndorsementChain.d.ts +2 -1
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/index.d.ts +7 -1
- package/dist/types/token-registry-functions/index.d.ts +9 -0
- package/dist/types/token-registry-functions/mint.d.ts +20 -0
- package/dist/types/token-registry-functions/ownerOf.d.ts +19 -0
- package/dist/types/token-registry-functions/rejectTransfers.d.ts +43 -0
- package/dist/types/token-registry-functions/returnToken.d.ts +44 -0
- package/dist/types/token-registry-functions/transfer.d.ts +82 -0
- package/dist/types/token-registry-functions/types.d.ts +80 -0
- package/dist/types/token-registry-functions/utils.d.ts +13 -0
- package/package.json +1 -1
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { getTitleEscrowAddress, encrypt, isTitleEscrowVersion, TitleEscrowInterface, checkSupportsInterface } from '../core';
|
|
2
|
+
import { v5Contracts, v5SupportInterfaceIds } from '../token-registry-v5';
|
|
3
|
+
import { v4Contracts, v4SupportInterfaceIds } from '../token-registry-v4';
|
|
4
|
+
import { getTxOptions } from './utils';
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
const returnToIssuer = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
9
|
+
const { tokenRegistryAddress, tokenId } = contractOptions;
|
|
10
|
+
let { titleEscrowAddress } = contractOptions;
|
|
11
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
12
|
+
if (!titleEscrowAddress) {
|
|
13
|
+
titleEscrowAddress = await getTitleEscrowAddress(
|
|
14
|
+
tokenRegistryAddress,
|
|
15
|
+
tokenId,
|
|
16
|
+
signer.provider,
|
|
17
|
+
{}
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
if (!titleEscrowAddress) throw new Error("Title Escrow address is required");
|
|
21
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
22
|
+
const { remarks } = params;
|
|
23
|
+
let titleEscrowContract = v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
|
|
24
|
+
const encryptedRemarks = remarks && options.id ? `0x${encrypt(remarks, options.id)}` : "0x";
|
|
25
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
26
|
+
let isV4TT = titleEscrowVersion === "v4";
|
|
27
|
+
if (titleEscrowVersion === void 0) {
|
|
28
|
+
[isV4TT, isV5TT] = await Promise.all([
|
|
29
|
+
await isTitleEscrowVersion({
|
|
30
|
+
titleEscrowAddress,
|
|
31
|
+
versionInterface: TitleEscrowInterface.V4,
|
|
32
|
+
provider: signer.provider
|
|
33
|
+
}),
|
|
34
|
+
await isTitleEscrowVersion({
|
|
35
|
+
titleEscrowAddress,
|
|
36
|
+
versionInterface: TitleEscrowInterface.V5,
|
|
37
|
+
provider: signer.provider
|
|
38
|
+
})
|
|
39
|
+
]);
|
|
40
|
+
}
|
|
41
|
+
if (!isV5TT && !isV4TT) {
|
|
42
|
+
throw new Error("Only Token Registry V4/V5 is supported");
|
|
43
|
+
}
|
|
44
|
+
if (isV4TT) {
|
|
45
|
+
titleEscrowContract = v4Contracts.TitleEscrow__factory.connect(
|
|
46
|
+
titleEscrowAddress,
|
|
47
|
+
signer
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
if (isV5TT) {
|
|
52
|
+
await titleEscrowContract.callStatic.returnToIssuer(
|
|
53
|
+
encryptedRemarks
|
|
54
|
+
);
|
|
55
|
+
} else if (isV4TT) {
|
|
56
|
+
await titleEscrowContract.callStatic.surrender();
|
|
57
|
+
}
|
|
58
|
+
} catch (e) {
|
|
59
|
+
console.error("callStatic failed:", e);
|
|
60
|
+
throw new Error("Pre-check (callStatic) for returnToIssuer failed");
|
|
61
|
+
}
|
|
62
|
+
const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
63
|
+
if (isV5TT) {
|
|
64
|
+
return await titleEscrowContract.returnToIssuer(
|
|
65
|
+
encryptedRemarks,
|
|
66
|
+
txOptions
|
|
67
|
+
);
|
|
68
|
+
} else if (isV4TT) {
|
|
69
|
+
return await titleEscrowContract.surrender(txOptions);
|
|
70
|
+
}
|
|
71
|
+
}, "returnToIssuer");
|
|
72
|
+
const rejectReturned = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
73
|
+
const { tokenRegistryAddress } = contractOptions;
|
|
74
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
75
|
+
if (!tokenRegistryAddress) throw new Error("Token registry address is required");
|
|
76
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
77
|
+
const { tokenId, remarks } = params;
|
|
78
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
79
|
+
let isV4TT = titleEscrowVersion === "v4";
|
|
80
|
+
if (titleEscrowVersion === void 0) {
|
|
81
|
+
[isV4TT, isV5TT] = await Promise.all([
|
|
82
|
+
checkSupportsInterface(
|
|
83
|
+
tokenRegistryAddress,
|
|
84
|
+
v4SupportInterfaceIds.TradeTrustTokenRestorable,
|
|
85
|
+
signer.provider
|
|
86
|
+
),
|
|
87
|
+
checkSupportsInterface(
|
|
88
|
+
tokenRegistryAddress,
|
|
89
|
+
v5SupportInterfaceIds.TradeTrustTokenRestorable,
|
|
90
|
+
signer.provider
|
|
91
|
+
)
|
|
92
|
+
]);
|
|
93
|
+
}
|
|
94
|
+
if (!isV4TT && !isV5TT) {
|
|
95
|
+
throw new Error("Only Token Registry V4/V5 is supported");
|
|
96
|
+
}
|
|
97
|
+
let tradeTrustTokenContract;
|
|
98
|
+
if (isV5TT) {
|
|
99
|
+
tradeTrustTokenContract = v5Contracts.TradeTrustToken__factory.connect(
|
|
100
|
+
tokenRegistryAddress,
|
|
101
|
+
signer
|
|
102
|
+
);
|
|
103
|
+
} else if (isV4TT) {
|
|
104
|
+
tradeTrustTokenContract = v4Contracts.TradeTrustToken__factory.connect(
|
|
105
|
+
tokenRegistryAddress,
|
|
106
|
+
signer
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
const encryptedRemarks = remarks && isV5TT ? `0x${encrypt(remarks, options.id)}` : "0x";
|
|
110
|
+
try {
|
|
111
|
+
if (isV5TT) {
|
|
112
|
+
await tradeTrustTokenContract.callStatic.restore(
|
|
113
|
+
tokenId,
|
|
114
|
+
encryptedRemarks
|
|
115
|
+
);
|
|
116
|
+
} else if (isV4TT) {
|
|
117
|
+
await tradeTrustTokenContract.callStatic.restore(tokenId);
|
|
118
|
+
}
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.error("callStatic failed:", e);
|
|
121
|
+
throw new Error("Pre-check (callStatic) for rejectReturned failed");
|
|
122
|
+
}
|
|
123
|
+
const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
124
|
+
if (isV5TT) {
|
|
125
|
+
return await tradeTrustTokenContract.restore(
|
|
126
|
+
tokenId,
|
|
127
|
+
encryptedRemarks,
|
|
128
|
+
txOptions
|
|
129
|
+
);
|
|
130
|
+
} else if (isV4TT) {
|
|
131
|
+
return await tradeTrustTokenContract.restore(
|
|
132
|
+
tokenId,
|
|
133
|
+
txOptions
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
}, "rejectReturned");
|
|
137
|
+
const acceptReturned = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
138
|
+
const { tokenRegistryAddress } = contractOptions;
|
|
139
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
140
|
+
if (!tokenRegistryAddress) throw new Error("Token registry address is required");
|
|
141
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
142
|
+
const { tokenId, remarks } = params;
|
|
143
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
144
|
+
let isV4TT = titleEscrowVersion === "v4";
|
|
145
|
+
if (titleEscrowVersion === void 0) {
|
|
146
|
+
[isV4TT, isV5TT] = await Promise.all([
|
|
147
|
+
checkSupportsInterface(
|
|
148
|
+
tokenRegistryAddress,
|
|
149
|
+
v4SupportInterfaceIds.TradeTrustTokenBurnable,
|
|
150
|
+
signer.provider
|
|
151
|
+
),
|
|
152
|
+
checkSupportsInterface(
|
|
153
|
+
tokenRegistryAddress,
|
|
154
|
+
v5SupportInterfaceIds.TradeTrustTokenBurnable,
|
|
155
|
+
signer.provider
|
|
156
|
+
)
|
|
157
|
+
]);
|
|
158
|
+
}
|
|
159
|
+
if (!isV4TT && !isV5TT) {
|
|
160
|
+
throw new Error("Only Token Registry V4/V5 is supported");
|
|
161
|
+
}
|
|
162
|
+
let tradeTrustTokenContract;
|
|
163
|
+
if (isV5TT) {
|
|
164
|
+
tradeTrustTokenContract = v5Contracts.TradeTrustToken__factory.connect(
|
|
165
|
+
tokenRegistryAddress,
|
|
166
|
+
signer
|
|
167
|
+
);
|
|
168
|
+
} else if (isV4TT) {
|
|
169
|
+
tradeTrustTokenContract = v4Contracts.TradeTrustToken__factory.connect(
|
|
170
|
+
tokenRegistryAddress,
|
|
171
|
+
signer
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
const encryptedRemarks = remarks && isV5TT ? `0x${encrypt(remarks, options.id)}` : "0x";
|
|
175
|
+
try {
|
|
176
|
+
if (isV5TT) {
|
|
177
|
+
await tradeTrustTokenContract.callStatic.burn(
|
|
178
|
+
tokenId,
|
|
179
|
+
encryptedRemarks
|
|
180
|
+
);
|
|
181
|
+
} else if (isV4TT) {
|
|
182
|
+
await tradeTrustTokenContract.callStatic.burn(tokenId);
|
|
183
|
+
}
|
|
184
|
+
} catch (e) {
|
|
185
|
+
console.error("callStatic failed:", e);
|
|
186
|
+
throw new Error("Pre-check (callStatic) for acceptReturned failed");
|
|
187
|
+
}
|
|
188
|
+
const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
189
|
+
if (isV5TT) {
|
|
190
|
+
return await tradeTrustTokenContract.burn(
|
|
191
|
+
tokenId,
|
|
192
|
+
encryptedRemarks,
|
|
193
|
+
txOptions
|
|
194
|
+
);
|
|
195
|
+
} else if (isV4TT) {
|
|
196
|
+
return await tradeTrustTokenContract.burn(tokenId, txOptions);
|
|
197
|
+
}
|
|
198
|
+
}, "acceptReturned");
|
|
199
|
+
|
|
200
|
+
export { acceptReturned, rejectReturned, returnToIssuer };
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { getTitleEscrowAddress, encrypt, isTitleEscrowVersion, TitleEscrowInterface } from '../core';
|
|
2
|
+
import { v4Contracts } from '../token-registry-v4';
|
|
3
|
+
import { v5Contracts } from '../token-registry-v5';
|
|
4
|
+
import { getTxOptions } from './utils';
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
const transferHolder = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
9
|
+
const { tokenRegistryAddress, tokenId } = contractOptions;
|
|
10
|
+
const { titleEscrowVersion } = options;
|
|
11
|
+
let { titleEscrowAddress } = contractOptions;
|
|
12
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
|
|
13
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
14
|
+
let isV4TT = titleEscrowVersion === "v4";
|
|
15
|
+
if (!titleEscrowAddress) {
|
|
16
|
+
titleEscrowAddress = await getTitleEscrowAddress(
|
|
17
|
+
tokenRegistryAddress,
|
|
18
|
+
tokenId,
|
|
19
|
+
signer.provider,
|
|
20
|
+
{ titleEscrowVersion }
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
if (!titleEscrowAddress) throw new Error("Token registry address is required");
|
|
24
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
25
|
+
const { holderAddress, remarks } = params;
|
|
26
|
+
let titleEscrowContract = v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
|
|
27
|
+
const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id)}` : "0x";
|
|
28
|
+
if (titleEscrowVersion === void 0) {
|
|
29
|
+
[isV4TT, isV5TT] = await Promise.all([
|
|
30
|
+
isTitleEscrowVersion({
|
|
31
|
+
titleEscrowAddress,
|
|
32
|
+
versionInterface: TitleEscrowInterface.V4,
|
|
33
|
+
provider: signer.provider
|
|
34
|
+
}),
|
|
35
|
+
isTitleEscrowVersion({
|
|
36
|
+
titleEscrowAddress,
|
|
37
|
+
versionInterface: TitleEscrowInterface.V5,
|
|
38
|
+
provider: signer.provider
|
|
39
|
+
})
|
|
40
|
+
]);
|
|
41
|
+
}
|
|
42
|
+
if (!isV4TT && !isV5TT) {
|
|
43
|
+
throw new Error("Only Token Registry V4/V5 is supported");
|
|
44
|
+
}
|
|
45
|
+
if (isV4TT) {
|
|
46
|
+
titleEscrowContract = v4Contracts.TitleEscrow__factory.connect(
|
|
47
|
+
titleEscrowAddress,
|
|
48
|
+
signer
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
if (isV5TT) {
|
|
53
|
+
await titleEscrowContract.callStatic.transferHolder(
|
|
54
|
+
holderAddress,
|
|
55
|
+
encryptedRemarks
|
|
56
|
+
);
|
|
57
|
+
} else if (isV4TT) {
|
|
58
|
+
await titleEscrowContract.callStatic.transferHolder(
|
|
59
|
+
holderAddress
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
} catch (e) {
|
|
63
|
+
console.error("callStatic failed:", e);
|
|
64
|
+
throw new Error("Pre-check (callStatic) for transferHolder failed");
|
|
65
|
+
}
|
|
66
|
+
const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
67
|
+
if (isV5TT) {
|
|
68
|
+
return await titleEscrowContract.transferHolder(
|
|
69
|
+
holderAddress,
|
|
70
|
+
encryptedRemarks,
|
|
71
|
+
txOptions
|
|
72
|
+
);
|
|
73
|
+
} else if (isV4TT) {
|
|
74
|
+
return await titleEscrowContract.transferHolder(
|
|
75
|
+
holderAddress,
|
|
76
|
+
txOptions
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}, "transferHolder");
|
|
80
|
+
const transferBeneficiary = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
81
|
+
const { tokenId, tokenRegistryAddress } = contractOptions;
|
|
82
|
+
const { titleEscrowVersion } = options;
|
|
83
|
+
let { titleEscrowAddress } = contractOptions;
|
|
84
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
|
|
85
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
86
|
+
let isV4TT = titleEscrowVersion === "v4";
|
|
87
|
+
if (!titleEscrowAddress) {
|
|
88
|
+
titleEscrowAddress = await getTitleEscrowAddress(
|
|
89
|
+
tokenRegistryAddress,
|
|
90
|
+
tokenId,
|
|
91
|
+
signer.provider,
|
|
92
|
+
{ titleEscrowVersion }
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
if (!titleEscrowAddress) throw new Error("Token registry address is required");
|
|
96
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
97
|
+
const { newBeneficiaryAddress, remarks } = params;
|
|
98
|
+
let titleEscrowContract = v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
|
|
99
|
+
const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id)}` : "0x";
|
|
100
|
+
if (titleEscrowVersion === void 0) {
|
|
101
|
+
[isV4TT, isV5TT] = await Promise.all([
|
|
102
|
+
isTitleEscrowVersion({
|
|
103
|
+
titleEscrowAddress,
|
|
104
|
+
versionInterface: TitleEscrowInterface.V4,
|
|
105
|
+
provider: signer.provider
|
|
106
|
+
}),
|
|
107
|
+
isTitleEscrowVersion({
|
|
108
|
+
titleEscrowAddress,
|
|
109
|
+
versionInterface: TitleEscrowInterface.V5,
|
|
110
|
+
provider: signer.provider
|
|
111
|
+
})
|
|
112
|
+
]);
|
|
113
|
+
}
|
|
114
|
+
if (!isV4TT && !isV5TT) {
|
|
115
|
+
throw new Error("Only Token Registry V4/V5 is supported");
|
|
116
|
+
}
|
|
117
|
+
if (!isV5TT) {
|
|
118
|
+
titleEscrowContract = v4Contracts.TitleEscrow__factory.connect(
|
|
119
|
+
titleEscrowAddress,
|
|
120
|
+
signer
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
if (isV5TT) {
|
|
125
|
+
await titleEscrowContract.callStatic.transferBeneficiary(
|
|
126
|
+
newBeneficiaryAddress,
|
|
127
|
+
encryptedRemarks
|
|
128
|
+
);
|
|
129
|
+
} else if (isV4TT) {
|
|
130
|
+
await titleEscrowContract.callStatic.transferBeneficiary(
|
|
131
|
+
newBeneficiaryAddress
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
} catch (e) {
|
|
135
|
+
console.error("callStatic failed:", e);
|
|
136
|
+
throw new Error("Pre-check (callStatic) for transferBeneficiary failed");
|
|
137
|
+
}
|
|
138
|
+
const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
139
|
+
if (isV5TT) {
|
|
140
|
+
const tx = await titleEscrowContract.transferBeneficiary(
|
|
141
|
+
newBeneficiaryAddress,
|
|
142
|
+
encryptedRemarks,
|
|
143
|
+
txOptions
|
|
144
|
+
);
|
|
145
|
+
return tx;
|
|
146
|
+
} else if (isV4TT) {
|
|
147
|
+
const tx = await titleEscrowContract.transferBeneficiary(
|
|
148
|
+
newBeneficiaryAddress,
|
|
149
|
+
txOptions
|
|
150
|
+
);
|
|
151
|
+
return tx;
|
|
152
|
+
}
|
|
153
|
+
}, "transferBeneficiary");
|
|
154
|
+
const transferOwners = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
155
|
+
const { tokenId, tokenRegistryAddress } = contractOptions;
|
|
156
|
+
const { titleEscrowVersion } = options;
|
|
157
|
+
let { titleEscrowAddress } = contractOptions;
|
|
158
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
|
|
159
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
160
|
+
let isV4TT = titleEscrowVersion === "v4";
|
|
161
|
+
if (!titleEscrowAddress) {
|
|
162
|
+
titleEscrowAddress = await getTitleEscrowAddress(
|
|
163
|
+
tokenRegistryAddress,
|
|
164
|
+
tokenId,
|
|
165
|
+
signer.provider,
|
|
166
|
+
{ titleEscrowVersion }
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
if (!titleEscrowAddress) throw new Error("Token registry address is required");
|
|
170
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
171
|
+
const { newBeneficiaryAddress, newHolderAddress, remarks } = params;
|
|
172
|
+
let titleEscrowContract = v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
|
|
173
|
+
const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id)}` : "0x";
|
|
174
|
+
if (titleEscrowVersion === void 0) {
|
|
175
|
+
[isV4TT, isV5TT] = await Promise.all([
|
|
176
|
+
isTitleEscrowVersion({
|
|
177
|
+
titleEscrowAddress,
|
|
178
|
+
versionInterface: TitleEscrowInterface.V4,
|
|
179
|
+
provider: signer.provider
|
|
180
|
+
}),
|
|
181
|
+
isTitleEscrowVersion({
|
|
182
|
+
titleEscrowAddress,
|
|
183
|
+
versionInterface: TitleEscrowInterface.V5,
|
|
184
|
+
provider: signer.provider
|
|
185
|
+
})
|
|
186
|
+
]);
|
|
187
|
+
}
|
|
188
|
+
if (!isV4TT && !isV5TT) {
|
|
189
|
+
throw new Error("Only Token Registry V4/V5 is supported");
|
|
190
|
+
}
|
|
191
|
+
if (!isV5TT) {
|
|
192
|
+
titleEscrowContract = v4Contracts.TitleEscrow__factory.connect(
|
|
193
|
+
titleEscrowAddress,
|
|
194
|
+
signer
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
try {
|
|
198
|
+
if (isV5TT) {
|
|
199
|
+
await titleEscrowContract.callStatic.transferOwners(
|
|
200
|
+
newBeneficiaryAddress,
|
|
201
|
+
newHolderAddress,
|
|
202
|
+
encryptedRemarks
|
|
203
|
+
);
|
|
204
|
+
} else if (isV4TT) {
|
|
205
|
+
await titleEscrowContract.callStatic.transferOwners(
|
|
206
|
+
newBeneficiaryAddress,
|
|
207
|
+
newHolderAddress
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
} catch (e) {
|
|
211
|
+
console.error("callStatic failed:", e);
|
|
212
|
+
throw new Error("Pre-check (callStatic) for transferOwners failed");
|
|
213
|
+
}
|
|
214
|
+
const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
215
|
+
if (isV5TT) {
|
|
216
|
+
return await titleEscrowContract.transferOwners(
|
|
217
|
+
newBeneficiaryAddress,
|
|
218
|
+
newHolderAddress,
|
|
219
|
+
encryptedRemarks,
|
|
220
|
+
txOptions
|
|
221
|
+
);
|
|
222
|
+
} else if (isV4TT) {
|
|
223
|
+
return await titleEscrowContract.transferOwners(
|
|
224
|
+
newBeneficiaryAddress,
|
|
225
|
+
newHolderAddress,
|
|
226
|
+
txOptions
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
}, "transferOwners");
|
|
230
|
+
const nominate = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
231
|
+
const { tokenId, tokenRegistryAddress } = contractOptions;
|
|
232
|
+
const { titleEscrowVersion } = options;
|
|
233
|
+
let { titleEscrowAddress } = contractOptions;
|
|
234
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
|
|
235
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
236
|
+
let isV4TT = titleEscrowVersion === "v4";
|
|
237
|
+
if (!titleEscrowAddress) {
|
|
238
|
+
titleEscrowAddress = await getTitleEscrowAddress(
|
|
239
|
+
tokenRegistryAddress,
|
|
240
|
+
tokenId,
|
|
241
|
+
signer.provider,
|
|
242
|
+
{ titleEscrowVersion }
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
if (!titleEscrowAddress) throw new Error("Token registry address is required");
|
|
246
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
247
|
+
const { newBeneficiaryAddress, remarks } = params;
|
|
248
|
+
let titleEscrowContract = v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
|
|
249
|
+
const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id)}` : "0x";
|
|
250
|
+
if (titleEscrowVersion === void 0) {
|
|
251
|
+
[isV4TT, isV5TT] = await Promise.all([
|
|
252
|
+
isTitleEscrowVersion({
|
|
253
|
+
titleEscrowAddress,
|
|
254
|
+
versionInterface: TitleEscrowInterface.V4,
|
|
255
|
+
provider: signer.provider
|
|
256
|
+
}),
|
|
257
|
+
isTitleEscrowVersion({
|
|
258
|
+
titleEscrowAddress,
|
|
259
|
+
versionInterface: TitleEscrowInterface.V5,
|
|
260
|
+
provider: signer.provider
|
|
261
|
+
})
|
|
262
|
+
]);
|
|
263
|
+
}
|
|
264
|
+
if (!isV5TT) {
|
|
265
|
+
titleEscrowContract = v4Contracts.TitleEscrow__factory.connect(
|
|
266
|
+
titleEscrowAddress,
|
|
267
|
+
signer
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
try {
|
|
271
|
+
if (isV5TT) {
|
|
272
|
+
await titleEscrowContract.callStatic.nominate(
|
|
273
|
+
newBeneficiaryAddress,
|
|
274
|
+
encryptedRemarks
|
|
275
|
+
);
|
|
276
|
+
} else if (isV4TT) {
|
|
277
|
+
await titleEscrowContract.callStatic.nominate(
|
|
278
|
+
newBeneficiaryAddress
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
} catch (e) {
|
|
282
|
+
console.error("callStatic failed:", e);
|
|
283
|
+
throw new Error("Pre-check (callStatic) for nominate failed");
|
|
284
|
+
}
|
|
285
|
+
const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
286
|
+
if (isV5TT) {
|
|
287
|
+
return await titleEscrowContract.nominate(
|
|
288
|
+
newBeneficiaryAddress,
|
|
289
|
+
encryptedRemarks,
|
|
290
|
+
txOptions
|
|
291
|
+
);
|
|
292
|
+
} else if (isV4TT) {
|
|
293
|
+
return await titleEscrowContract.nominate(
|
|
294
|
+
newBeneficiaryAddress,
|
|
295
|
+
txOptions
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
}, "nominate");
|
|
299
|
+
|
|
300
|
+
export { nominate, transferBeneficiary, transferHolder, transferOwners };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isV6EthersProvider } from '../utils/ethers';
|
|
2
|
+
import { SUPPORTED_CHAINS } from '@tradetrust-tt/tradetrust-utils';
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
const getTxOptions = /* @__PURE__ */ __name(async (signer, chainId, maxFeePerGas, maxPriorityFeePerGas) => {
|
|
7
|
+
if (!maxFeePerGas || !maxPriorityFeePerGas) {
|
|
8
|
+
chainId = chainId ?? await getChainIdSafe(signer);
|
|
9
|
+
const gasStation = SUPPORTED_CHAINS[chainId]?.gasStation;
|
|
10
|
+
if (gasStation) {
|
|
11
|
+
const gasFees = await gasStation();
|
|
12
|
+
maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
|
|
13
|
+
maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
|
|
17
|
+
}, "getTxOptions");
|
|
18
|
+
const getChainIdSafe = /* @__PURE__ */ __name(async (signer) => {
|
|
19
|
+
if (isV6EthersProvider(signer.provider)) {
|
|
20
|
+
const network = await signer.provider?.getNetwork();
|
|
21
|
+
if (!network?.chainId) throw new Error("Cannot determine chainId: provider is missing");
|
|
22
|
+
return network.chainId;
|
|
23
|
+
}
|
|
24
|
+
return await signer.getChainId();
|
|
25
|
+
}, "getChainIdSafe");
|
|
26
|
+
const getSignerAddressSafe = /* @__PURE__ */ __name(async (signer) => {
|
|
27
|
+
if (isV6EthersProvider(signer.provider)) {
|
|
28
|
+
return await signer.getAddress();
|
|
29
|
+
}
|
|
30
|
+
return await signer.getAddress();
|
|
31
|
+
}, "getSignerAddressSafe");
|
|
32
|
+
|
|
33
|
+
export { getChainIdSafe, getSignerAddressSafe, getTxOptions };
|
|
@@ -3,7 +3,7 @@ export { fetchTokenTransfers } from './fetchTokenTransfer.js';
|
|
|
3
3
|
export { fetchEventTime, mergeTransfersV4, mergeTransfersV5, sortLogChain } from './helpers.js';
|
|
4
4
|
export { getEndorsementChain } from './retrieveEndorsementChain.js';
|
|
5
5
|
export { EndorsementChain, ParsedLog, TitleEscrowTransferEvent, TitleEscrowTransferEventType, TokenTransferEvent, TokenTransferEventType, TradeTrustTokenEventType, TransferBaseEvent, TransferEvent, TransferEventType, TypedEvent } from './types.js';
|
|
6
|
-
export { TitleEscrowInterface, fetchEndorsementChain, getDocumentOwner, getTitleEscrowAddress, isTitleEscrowVersion } from './useEndorsementChain.js';
|
|
6
|
+
export { TitleEscrowInterface, checkSupportsInterface, fetchEndorsementChain, getDocumentOwner, getTitleEscrowAddress, isTitleEscrowVersion } from './useEndorsementChain.js';
|
|
7
7
|
import 'ethersV6';
|
|
8
8
|
import '@ethersproject/abstract-provider';
|
|
9
9
|
import 'ethers';
|
|
@@ -12,6 +12,7 @@ declare const getTitleEscrowAddress: (tokenRegistryAddress: string, tokenId: str
|
|
|
12
12
|
titleEscrowVersion?: "v4" | "v5";
|
|
13
13
|
}) => Promise<string>;
|
|
14
14
|
declare const getDocumentOwner: (tokenRegistryAddress: string, tokenId: string, provider: Provider | ethers.Provider) => Promise<string>;
|
|
15
|
+
declare const checkSupportsInterface: (contractAddress: string, interfaceId: string, provider: Provider | ethers.Provider) => Promise<boolean>;
|
|
15
16
|
interface TitleEscrowVersionParams {
|
|
16
17
|
tokenRegistryAddress?: string;
|
|
17
18
|
tokenId?: string;
|
|
@@ -27,4 +28,4 @@ interface TitleEscrowVersionParams {
|
|
|
27
28
|
declare const isTitleEscrowVersion: ({ tokenRegistryAddress, tokenId, titleEscrowAddress, versionInterface, provider, }: TitleEscrowVersionParams) => Promise<boolean>;
|
|
28
29
|
declare const fetchEndorsementChain: (tokenRegistryAddress: string, tokenId: string, provider: Provider | ethers.Provider, keyId?: string) => Promise<EndorsementChain>;
|
|
29
30
|
|
|
30
|
-
export { TitleEscrowInterface, fetchEndorsementChain, getDocumentOwner, getTitleEscrowAddress, isTitleEscrowVersion };
|
|
31
|
+
export { TitleEscrowInterface, checkSupportsInterface, fetchEndorsementChain, getDocumentOwner, getTitleEscrowAddress, isTitleEscrowVersion };
|
|
@@ -6,7 +6,7 @@ export { fetchTokenTransfers } from './endorsement-chain/fetchTokenTransfer.js';
|
|
|
6
6
|
export { fetchEventTime, mergeTransfersV4, mergeTransfersV5, sortLogChain } from './endorsement-chain/helpers.js';
|
|
7
7
|
export { getEndorsementChain } from './endorsement-chain/retrieveEndorsementChain.js';
|
|
8
8
|
export { EndorsementChain, ParsedLog, TitleEscrowTransferEvent, TitleEscrowTransferEventType, TokenTransferEvent, TokenTransferEventType, TradeTrustTokenEventType, TransferBaseEvent, TransferEvent, TransferEventType, TypedEvent } from './endorsement-chain/types.js';
|
|
9
|
-
export { TitleEscrowInterface, fetchEndorsementChain, getDocumentOwner, getTitleEscrowAddress, isTitleEscrowVersion } from './endorsement-chain/useEndorsementChain.js';
|
|
9
|
+
export { TitleEscrowInterface, checkSupportsInterface, fetchEndorsementChain, getDocumentOwner, getTitleEscrowAddress, isTitleEscrowVersion } from './endorsement-chain/useEndorsementChain.js';
|
|
10
10
|
export { DocumentBuilder, RenderMethod, W3CTransferableRecordsConfig, W3CVerifiableDocumentConfig, qrCode } from './documentBuilder.js';
|
|
11
11
|
import '@trustvc/w3c-vc';
|
|
12
12
|
import 'ethers';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -10,6 +10,11 @@ export { supportInterfaceIds as v5SupportInterfaceIds } from './token-registry-v
|
|
|
10
10
|
export { c as v5Contracts } from './contracts-BaIGKzNt.js';
|
|
11
11
|
export { computeInterfaceId as v5ComputeInterfaceId, encodeInitParams as v5EncodeInitParams, getEventFromReceipt as v5GetEventFromReceipt } from './token-registry-v5/utils.js';
|
|
12
12
|
export { TypedContractMethod } from '@tradetrust-tt/token-registry-v5/contracts/common';
|
|
13
|
+
export { nominate, transferBeneficiary, transferHolder, transferOwners } from './token-registry-functions/transfer.js';
|
|
14
|
+
export { rejectTransferBeneficiary, rejectTransferHolder, rejectTransferOwners } from './token-registry-functions/rejectTransfers.js';
|
|
15
|
+
export { acceptReturned, rejectReturned, returnToIssuer } from './token-registry-functions/returnToken.js';
|
|
16
|
+
export { mint } from './token-registry-functions/mint.js';
|
|
17
|
+
export { ownerOf } from './token-registry-functions/ownerOf.js';
|
|
13
18
|
export { decrypt } from './core/decrypt.js';
|
|
14
19
|
export { encrypt } from './core/encrypt.js';
|
|
15
20
|
export { verifyDocument } from './core/verify.js';
|
|
@@ -18,7 +23,7 @@ export { fetchTokenTransfers } from './core/endorsement-chain/fetchTokenTransfer
|
|
|
18
23
|
export { fetchEventTime, mergeTransfersV4, mergeTransfersV5, sortLogChain } from './core/endorsement-chain/helpers.js';
|
|
19
24
|
export { getEndorsementChain } from './core/endorsement-chain/retrieveEndorsementChain.js';
|
|
20
25
|
export { EndorsementChain, ParsedLog, TitleEscrowTransferEvent, TitleEscrowTransferEventType, TokenTransferEvent, TokenTransferEventType, TradeTrustTokenEventType, TransferBaseEvent, TransferEvent, TransferEventType, TypedEvent } from './core/endorsement-chain/types.js';
|
|
21
|
-
export { TitleEscrowInterface, fetchEndorsementChain, getDocumentOwner, getTitleEscrowAddress, isTitleEscrowVersion } from './core/endorsement-chain/useEndorsementChain.js';
|
|
26
|
+
export { TitleEscrowInterface, checkSupportsInterface, fetchEndorsementChain, getDocumentOwner, getTitleEscrowAddress, isTitleEscrowVersion } from './core/endorsement-chain/useEndorsementChain.js';
|
|
22
27
|
export { DocumentBuilder, RenderMethod, W3CTransferableRecordsConfig, W3CVerifiableDocumentConfig, qrCode } from './core/documentBuilder.js';
|
|
23
28
|
export { signOA } from './open-attestation/sign.js';
|
|
24
29
|
export { KeyPair } from './open-attestation/types.js';
|
|
@@ -53,6 +58,7 @@ import '@typechain/ethers-v5/static/common';
|
|
|
53
58
|
import '@tradetrust-tt/token-registry-v5/contracts';
|
|
54
59
|
import '@tradetrust-tt/token-registry-v5';
|
|
55
60
|
import 'ethersV6';
|
|
61
|
+
import './token-registry-functions/types.js';
|
|
56
62
|
import '@ethersproject/abstract-provider';
|
|
57
63
|
import 'ethers/lib/utils';
|
|
58
64
|
import '@ethersproject/abstract-signer';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { nominate, transferBeneficiary, transferHolder, transferOwners } from './transfer.js';
|
|
2
|
+
export { rejectTransferBeneficiary, rejectTransferHolder, rejectTransferOwners } from './rejectTransfers.js';
|
|
3
|
+
export { acceptReturned, rejectReturned, returnToIssuer } from './returnToken.js';
|
|
4
|
+
export { mint } from './mint.js';
|
|
5
|
+
export { ownerOf } from './ownerOf.js';
|
|
6
|
+
import 'ethersV6';
|
|
7
|
+
import 'ethers';
|
|
8
|
+
import './types.js';
|
|
9
|
+
import '@tradetrust-tt/tradetrust-utils';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Signer as Signer$1 } from 'ethersV6';
|
|
2
|
+
import { Signer, ContractTransaction } from 'ethers';
|
|
3
|
+
import { MintTokenOptions, MintTokenParams, TransactionOptions } from './types.js';
|
|
4
|
+
import '@tradetrust-tt/tradetrust-utils';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Mints a new token into the TradeTrustToken registry with the specified beneficiary and holder.
|
|
8
|
+
* Supports both Token Registry V4 and V5 contracts.
|
|
9
|
+
* @param {MintTokenOptions} contractOptions - Contains the `tokenRegistryAddress` for the minting contract.
|
|
10
|
+
* @param {Signer | SignerV6} signer - Signer instance (Ethers v5 or v6) that authorizes the mint transaction.
|
|
11
|
+
* @param {MintTokenParams} params - Parameters for minting, including `beneficiaryAddress`, `holderAddress`, `tokenId`, and optional `remarks`.
|
|
12
|
+
* @param {TransactionOptions} options - Transaction metadata including gas values, version detection, chain ID, and optional encryption ID.
|
|
13
|
+
* @returns {Promise<ContractTransaction>} A promise resolving to the transaction result from the mint call.
|
|
14
|
+
* @throws {Error} If the token registry address or signer provider is not provided.
|
|
15
|
+
* @throws {Error} If neither V4 nor V5 interfaces are supported.
|
|
16
|
+
* @throws {Error} If the `callStatic.mint` fails as a pre-check.
|
|
17
|
+
*/
|
|
18
|
+
declare const mint: (contractOptions: MintTokenOptions, signer: Signer | Signer$1, params: MintTokenParams, options: TransactionOptions) => Promise<ContractTransaction>;
|
|
19
|
+
|
|
20
|
+
export { mint };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Signer as Signer$1 } from 'ethersV6';
|
|
2
|
+
import { Signer } from 'ethers';
|
|
3
|
+
import { OwnerOfTokenOptions, OwnerOfTokenParams, TransactionOptions } from './types.js';
|
|
4
|
+
import '@tradetrust-tt/tradetrust-utils';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Retrieves the owner of a given token from the TradeTrustToken contract.
|
|
8
|
+
* Supports both Token Registry V4 and V5 implementations.
|
|
9
|
+
* @param {OwnerOfTokenOptions} contractOptions - Options containing the token registry address.
|
|
10
|
+
* @param {Signer | SignerV6} signer - Signer instance (v5 or v6) used to query the blockchain.
|
|
11
|
+
* @param {OwnerOfTokenParams} params - Contains the `tokenId` of the token to query ownership for.
|
|
12
|
+
* @param {TransactionOptions} options - Includes the `titleEscrowVersion` and other optional metadata for interface detection.
|
|
13
|
+
* @returns {Promise<string>} A promise that resolves to the owner address of the specified token.
|
|
14
|
+
* @throws {Error} If token registry address or signer provider is not provided.
|
|
15
|
+
* @throws {Error} If the token registry does not support V4 or V5 interfaces.
|
|
16
|
+
*/
|
|
17
|
+
declare const ownerOf: (contractOptions: OwnerOfTokenOptions, signer: Signer | Signer$1, params: OwnerOfTokenParams, options: TransactionOptions) => Promise<string>;
|
|
18
|
+
|
|
19
|
+
export { ownerOf };
|