@ocap/client 1.25.3 → 1.25.5
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/README.md +76 -80
- package/dist/report.html +1 -1
- package/docs/_sidebar.md +22 -0
- package/docs/api-reference-client-methods.ja.md +229 -0
- package/docs/api-reference-client-methods.md +229 -0
- package/docs/api-reference-client-methods.zh-TW.md +229 -0
- package/docs/api-reference-client-methods.zh.md +229 -0
- package/docs/api-reference-data-types.ja.md +482 -0
- package/docs/api-reference-data-types.md +482 -0
- package/docs/api-reference-data-types.zh-TW.md +482 -0
- package/docs/api-reference-data-types.zh.md +482 -0
- package/docs/api-reference-low-level-api.ja.md +228 -0
- package/docs/api-reference-low-level-api.md +228 -0
- package/docs/api-reference-low-level-api.zh-TW.md +228 -0
- package/docs/api-reference-low-level-api.zh.md +228 -0
- package/docs/api-reference-query-mutation-methods.ja.md +814 -0
- package/docs/api-reference-query-mutation-methods.md +814 -0
- package/docs/api-reference-query-mutation-methods.zh-TW.md +814 -0
- package/docs/api-reference-query-mutation-methods.zh.md +814 -0
- package/docs/api-reference-transaction-helpers.ja.md +649 -0
- package/docs/api-reference-transaction-helpers.md +649 -0
- package/docs/api-reference-transaction-helpers.zh-TW.md +649 -0
- package/docs/api-reference-transaction-helpers.zh.md +649 -0
- package/docs/api-reference.ja.md +23 -0
- package/docs/api-reference.md +23 -0
- package/docs/api-reference.zh-TW.md +23 -0
- package/docs/api-reference.zh.md +23 -0
- package/docs/core-concepts-client-architecture.ja.md +102 -0
- package/docs/core-concepts-client-architecture.md +102 -0
- package/docs/core-concepts-client-architecture.zh-TW.md +102 -0
- package/docs/core-concepts-client-architecture.zh.md +102 -0
- package/docs/core-concepts-event-subscriptions.ja.md +123 -0
- package/docs/core-concepts-event-subscriptions.md +123 -0
- package/docs/core-concepts-event-subscriptions.zh-TW.md +123 -0
- package/docs/core-concepts-event-subscriptions.zh.md +123 -0
- package/docs/core-concepts-gas-payment.ja.md +111 -0
- package/docs/core-concepts-gas-payment.md +111 -0
- package/docs/core-concepts-gas-payment.zh-TW.md +111 -0
- package/docs/core-concepts-gas-payment.zh.md +111 -0
- package/docs/core-concepts-transaction-lifecycle.ja.md +183 -0
- package/docs/core-concepts-transaction-lifecycle.md +183 -0
- package/docs/core-concepts-transaction-lifecycle.zh-TW.md +183 -0
- package/docs/core-concepts-transaction-lifecycle.zh.md +183 -0
- package/docs/core-concepts.ja.md +22 -0
- package/docs/core-concepts.md +22 -0
- package/docs/core-concepts.zh-TW.md +22 -0
- package/docs/core-concepts.zh.md +22 -0
- package/docs/getting-started-basic-usage.ja.md +87 -0
- package/docs/getting-started-basic-usage.md +87 -0
- package/docs/getting-started-basic-usage.zh-TW.md +87 -0
- package/docs/getting-started-basic-usage.zh.md +87 -0
- package/docs/getting-started-installation.ja.md +60 -0
- package/docs/getting-started-installation.md +60 -0
- package/docs/getting-started-installation.zh-TW.md +60 -0
- package/docs/getting-started-installation.zh.md +60 -0
- package/docs/getting-started.ja.md +16 -0
- package/docs/getting-started.md +16 -0
- package/docs/getting-started.zh-TW.md +16 -0
- package/docs/getting-started.zh.md +17 -0
- package/docs/how-to-guides-delegate-permissions.ja.md +167 -0
- package/docs/how-to-guides-delegate-permissions.md +167 -0
- package/docs/how-to-guides-delegate-permissions.zh-TW.md +167 -0
- package/docs/how-to-guides-delegate-permissions.zh.md +166 -0
- package/docs/how-to-guides-manage-accounts.ja.md +73 -0
- package/docs/how-to-guides-manage-accounts.md +73 -0
- package/docs/how-to-guides-manage-accounts.zh-TW.md +73 -0
- package/docs/how-to-guides-manage-accounts.zh.md +73 -0
- package/docs/how-to-guides-manage-assets.ja.md +255 -0
- package/docs/how-to-guides-manage-assets.md +255 -0
- package/docs/how-to-guides-manage-assets.zh-TW.md +255 -0
- package/docs/how-to-guides-manage-assets.zh.md +255 -0
- package/docs/how-to-guides-manage-tokens.ja.md +179 -0
- package/docs/how-to-guides-manage-tokens.md +179 -0
- package/docs/how-to-guides-manage-tokens.zh-TW.md +179 -0
- package/docs/how-to-guides-manage-tokens.zh.md +179 -0
- package/docs/how-to-guides-stake-tokens-and-assets.ja.md +205 -0
- package/docs/how-to-guides-stake-tokens-and-assets.md +205 -0
- package/docs/how-to-guides-stake-tokens-and-assets.zh-TW.md +205 -0
- package/docs/how-to-guides-stake-tokens-and-assets.zh.md +205 -0
- package/docs/how-to-guides-transfer-tokens-and-nfts.ja.md +179 -0
- package/docs/how-to-guides-transfer-tokens-and-nfts.md +179 -0
- package/docs/how-to-guides-transfer-tokens-and-nfts.zh-TW.md +179 -0
- package/docs/how-to-guides-transfer-tokens-and-nfts.zh.md +179 -0
- package/docs/how-to-guides.ja.md +27 -0
- package/docs/how-to-guides.md +27 -0
- package/docs/how-to-guides.zh-TW.md +27 -0
- package/docs/how-to-guides.zh.md +27 -0
- package/docs/overview.ja.md +70 -0
- package/docs/overview.md +70 -0
- package/docs/overview.zh-TW.md +70 -0
- package/docs/overview.zh.md +70 -0
- package/package.json +14 -14
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# Delegate Permissions
|
|
2
|
+
|
|
3
|
+
Delegating permissions is a powerful feature that allows one account (the delegator) to authorize another account (the delegatee) to send specific types of transactions on its behalf. This is particularly useful for applications that need to perform actions for a user without having direct access to the user's primary private key. For example, you could delegate permission to an application-specific key to transfer certain assets or interact with a smart contract, enhancing security by limiting the scope of the key's authority.
|
|
4
|
+
|
|
5
|
+
This guide will walk you through granting, using, and revoking delegations.
|
|
6
|
+
|
|
7
|
+
## Granting Delegation
|
|
8
|
+
|
|
9
|
+
To authorize another account, you use the `delegate` method. You must specify who you are delegating to and which specific transaction types they are allowed to send. Each permission can also have limits, such as which tokens or assets can be involved.
|
|
10
|
+
|
|
11
|
+
### Parameters
|
|
12
|
+
|
|
13
|
+
<x-field-group>
|
|
14
|
+
<x-field data-name="from" data-type="WalletObject" data-required="true">
|
|
15
|
+
<x-field-desc markdown>The wallet object of the delegator (the account granting permissions).</x-field-desc>
|
|
16
|
+
</x-field>
|
|
17
|
+
<x-field data-name="to" data-type="WalletObject" data-required="true">
|
|
18
|
+
<x-field-desc markdown>The wallet object of the delegatee (the account receiving permissions).</x-field-desc>
|
|
19
|
+
</x-field>
|
|
20
|
+
<x-field data-name="privileges" data-type="Array<object>" data-required="true">
|
|
21
|
+
<x-field-desc markdown>An array of permission objects to grant. Each object defines a specific authorization.</x-field-desc>
|
|
22
|
+
<x-field data-name="typeUrl" data-type="string" data-required="true">
|
|
23
|
+
<x-field-desc markdown>The type URL of the transaction being permitted (e.g., `fg:t:transfer_v2`).</x-field-desc>
|
|
24
|
+
</x-field>
|
|
25
|
+
<x-field data-name="limit" data-type="object" data-required="false">
|
|
26
|
+
<x-field-desc markdown>Optional limits on the permission, such as restricting it to specific tokens or assets.</x-field-desc>
|
|
27
|
+
<x-field data-name="tokens" data-type="Array<string>" data-required="false" data-desc="An array of token addresses that this permission applies to."></x-field>
|
|
28
|
+
<x-field data-name="assets" data-type="Array<string>" data-required="false" data-desc="An array of asset addresses that this permission applies to."></x-field>
|
|
29
|
+
</x-field>
|
|
30
|
+
</x-field>
|
|
31
|
+
</x-field-group>
|
|
32
|
+
|
|
33
|
+
### Returns
|
|
34
|
+
|
|
35
|
+
<x-field data-name="result" data-type="Promise<[string, string]>" data-desc="A promise that resolves to an array containing the transaction hash and the newly created delegate address."></x-field>
|
|
36
|
+
|
|
37
|
+
### Example
|
|
38
|
+
|
|
39
|
+
Here’s how to delegate the `transfer` permission from one account to another.
|
|
40
|
+
|
|
41
|
+
```javascript Granting transfer permission icon=logos:javascript
|
|
42
|
+
import Client from '@ocap/client';
|
|
43
|
+
import { fromRandom } from '@ocap/wallet';
|
|
44
|
+
import { typeUrls } from '@ocap/proto';
|
|
45
|
+
|
|
46
|
+
const client = new Client('https://beta.abtnetwork.io/api');
|
|
47
|
+
|
|
48
|
+
// The account granting permission
|
|
49
|
+
const delegatorWallet = fromRandom();
|
|
50
|
+
|
|
51
|
+
// The account receiving permission
|
|
52
|
+
const delegateeWallet = fromRandom();
|
|
53
|
+
|
|
54
|
+
async function grantPermission() {
|
|
55
|
+
try {
|
|
56
|
+
// First, ensure the delegator account has funds.
|
|
57
|
+
// In a real application, you would transfer funds to delegatorWallet.address
|
|
58
|
+
// from a faucet or another account.
|
|
59
|
+
console.log(`Delegator address: ${delegatorWallet.address}`);
|
|
60
|
+
console.log(`Delegatee address: ${delegateeWallet.address}`);
|
|
61
|
+
console.log('Please fund the delegator account before proceeding.');
|
|
62
|
+
|
|
63
|
+
const privileges = [
|
|
64
|
+
{
|
|
65
|
+
typeUrl: typeUrls.TransferV2Tx,
|
|
66
|
+
// No limits specified, allowing transfer of any token/asset
|
|
67
|
+
limit: { tokens: [], assets: [] },
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
const [hash, delegateAddress] = await client.delegate({
|
|
72
|
+
from: delegatorWallet,
|
|
73
|
+
to: delegateeWallet,
|
|
74
|
+
privileges: privileges,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
console.log('Delegation successful!');
|
|
78
|
+
console.log('Transaction Hash:', hash);
|
|
79
|
+
console.log('Delegate Address:', delegateAddress);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error('Error delegating permissions:', error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
grantPermission();
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Sending a Transaction as a Delegatee
|
|
89
|
+
|
|
90
|
+
Once delegated, the delegatee wallet can send the authorized transaction by specifying the `delegator`'s address in the transaction parameters. The transaction is signed by the delegatee, but executed on behalf of the delegator, and the transaction fees are paid from the delegator's account.
|
|
91
|
+
|
|
92
|
+
### Example
|
|
93
|
+
|
|
94
|
+
```javascript Sending a transfer as a delegatee icon=logos:javascript
|
|
95
|
+
// Assuming the grantPermission() function from the previous example was successful
|
|
96
|
+
|
|
97
|
+
// The recipient of the transfer
|
|
98
|
+
const recipientWallet = fromRandom();
|
|
99
|
+
|
|
100
|
+
async function sendDelegatedTransaction() {
|
|
101
|
+
try {
|
|
102
|
+
const hash = await client.transfer({
|
|
103
|
+
to: recipientWallet.address,
|
|
104
|
+
token: 1, // Transfer 1 of the chain's native token
|
|
105
|
+
wallet: delegateeWallet, // Signed by the delegatee
|
|
106
|
+
delegator: delegatorWallet.address, // Executed on behalf of the delegator
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
console.log('Delegated transfer successful!');
|
|
110
|
+
console.log('Transaction Hash:', hash);
|
|
111
|
+
console.log(`Check transaction at: https://beta.abtnetwork.io/explorer/txs/${hash}`);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error('Error sending delegated transaction:', error);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Make sure to call this after the delegation is confirmed on-chain.
|
|
118
|
+
// sendDelegatedTransaction();
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Revoking Delegation
|
|
122
|
+
|
|
123
|
+
The delegator can revoke any granted permissions at any time using the `revokeDelegate` method. You need to specify which transaction types to revoke for a given delegatee.
|
|
124
|
+
|
|
125
|
+
### Parameters
|
|
126
|
+
|
|
127
|
+
<x-field-group>
|
|
128
|
+
<x-field data-name="from" data-type="WalletObject" data-required="true">
|
|
129
|
+
<x-field-desc markdown>The wallet object of the delegator who originally granted the permissions.</x-field-desc>
|
|
130
|
+
</x-field>
|
|
131
|
+
<x-field data-name="to" data-type="WalletObject" data-required="true">
|
|
132
|
+
<x-field-desc markdown>The wallet object of the delegatee whose permissions are being revoked.</x-field-desc>
|
|
133
|
+
</x-field>
|
|
134
|
+
<x-field data-name="privileges" data-type="Array<string>" data-required="true">
|
|
135
|
+
<x-field-desc markdown>An array of transaction `typeUrl` strings to revoke.</x-field-desc>
|
|
136
|
+
</x-field>
|
|
137
|
+
</x-field-group>
|
|
138
|
+
|
|
139
|
+
### Returns
|
|
140
|
+
|
|
141
|
+
<x-field data-name="hash" data-type="Promise<string>" data-desc="A promise that resolves to the transaction hash for the revocation."></x-field>
|
|
142
|
+
|
|
143
|
+
### Example
|
|
144
|
+
|
|
145
|
+
```javascript Revoking transfer permission icon=logos:javascript
|
|
146
|
+
// Assuming the same delegatorWallet and delegateeWallet from previous examples
|
|
147
|
+
|
|
148
|
+
async function revokePermission() {
|
|
149
|
+
try {
|
|
150
|
+
const hash = await client.revokeDelegate({
|
|
151
|
+
from: delegatorWallet,
|
|
152
|
+
to: delegateeWallet,
|
|
153
|
+
privileges: [typeUrls.TransferV2Tx], // The list of permissions to revoke
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
console.log('Revocation successful!');
|
|
157
|
+
console.log('Transaction Hash:', hash);
|
|
158
|
+
console.log(`Check transaction at: https://beta.abtnetwork.io/explorer/txs/${hash}`);
|
|
159
|
+
} catch (error) {
|
|
160
|
+
console.error('Error revoking delegation:', error);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// revokePermission();
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
After this transaction is confirmed, the `delegateeWallet` will no longer be able to send `transfer` transactions on behalf of the `delegatorWallet`.
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# 委派權限
|
|
2
|
+
|
|
3
|
+
委派權限是一項強大的功能,它允許一個帳戶(委派人)授權另一個帳戶(受派人)代表其發送特定類型的交易。這對於需要為使用者執行操作但又不想直接存取使用者主私鑰的應用程式特別有用。例如,您可以將權限委派給特定於應用程式的金鑰,以轉移某些資產或與智慧合約互動,透過限制金鑰的權限範圍來增強安全性。
|
|
4
|
+
|
|
5
|
+
本指南將引導您完成授予、使用和撤銷委派的過程。
|
|
6
|
+
|
|
7
|
+
## 授予委派
|
|
8
|
+
|
|
9
|
+
要授權另一個帳戶,您可以使用 `delegate` 方法。您必須指定要委派給誰以及他們被允許發送哪些特定的交易類型。每項權限還可以有其限制,例如可以涉及哪些代幣或資產。
|
|
10
|
+
|
|
11
|
+
### 參數
|
|
12
|
+
|
|
13
|
+
<x-field-group>
|
|
14
|
+
<x-field data-name="from" data-type="WalletObject" data-required="true">
|
|
15
|
+
<x-field-desc markdown>委派人(授予權限的帳戶)的錢包物件。</x-field-desc>
|
|
16
|
+
</x-field>
|
|
17
|
+
<x-field data-name="to" data-type="WalletObject" data-required="true">
|
|
18
|
+
<x-field-desc markdown>受派人(接收權限的帳戶)的錢包物件。</x-field-desc>
|
|
19
|
+
</x-field>
|
|
20
|
+
<x-field data-name="privileges" data-type="Array<object>" data-required="true">
|
|
21
|
+
<x-field-desc markdown>要授予的權限物件陣列。每個物件定義一個特定的授權。</x-field-desc>
|
|
22
|
+
<x-field data-name="typeUrl" data-type="string" data-required="true">
|
|
23
|
+
<x-field-desc markdown>被允許的交易的類型 URL(例如 `fg:t:transfer_v2`)。</x-field-desc>
|
|
24
|
+
</x-field>
|
|
25
|
+
<x-field data-name="limit" data-type="object" data-required="false">
|
|
26
|
+
<x-field-desc markdown>對權限的可選限制,例如將其限制為特定的代幣或資產。</x-field-desc>
|
|
27
|
+
<x-field data-name="tokens" data-type="Array<string>" data-required="false" data-desc="此權限適用的代幣地址陣列。"></x-field>
|
|
28
|
+
<x-field data-name="assets" data-type="Array<string>" data-required="false" data-desc="此權限適用的資產地址陣列。"></x-field>
|
|
29
|
+
</x-field>
|
|
30
|
+
</x-field>
|
|
31
|
+
</x-field-group>
|
|
32
|
+
|
|
33
|
+
### 返回值
|
|
34
|
+
|
|
35
|
+
<x-field data-name="result" data-type="Promise<[string, string]>" data-desc="一個解析為包含交易雜湊和新建立的委派地址的陣列的 Promise。"></x-field>
|
|
36
|
+
|
|
37
|
+
### 範例
|
|
38
|
+
|
|
39
|
+
以下是如何將 `transfer` 權限從一個帳戶委派給另一個帳戶的方法。
|
|
40
|
+
|
|
41
|
+
```javascript Granting transfer permission icon=logos:javascript
|
|
42
|
+
import Client from '@ocap/client';
|
|
43
|
+
import { fromRandom } from '@ocap/wallet';
|
|
44
|
+
import { typeUrls } from '@ocap/proto';
|
|
45
|
+
|
|
46
|
+
const client = new Client('https://beta.abtnetwork.io/api');
|
|
47
|
+
|
|
48
|
+
// 授予權限的帳戶
|
|
49
|
+
const delegatorWallet = fromRandom();
|
|
50
|
+
|
|
51
|
+
// 接收權限的帳戶
|
|
52
|
+
const delegateeWallet = fromRandom();
|
|
53
|
+
|
|
54
|
+
async function grantPermission() {
|
|
55
|
+
try {
|
|
56
|
+
// 首先,確保委派人帳戶有資金。
|
|
57
|
+
// 在實際應用中,您需要將資金從水龍頭或其他帳戶轉入 delegatorWallet.address
|
|
58
|
+
// from a faucet or another account.
|
|
59
|
+
console.log(`Delegator address: ${delegatorWallet.address}`);
|
|
60
|
+
console.log(`Delegatee address: ${delegateeWallet.address}`);
|
|
61
|
+
console.log('Please fund the delegator account before proceeding.');
|
|
62
|
+
|
|
63
|
+
const privileges = [
|
|
64
|
+
{
|
|
65
|
+
typeUrl: typeUrls.TransferV2Tx,
|
|
66
|
+
// 未指定限制,允許轉移任何代幣/資產
|
|
67
|
+
limit: { tokens: [], assets: [] },
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
const [hash, delegateAddress] = await client.delegate({
|
|
72
|
+
from: delegatorWallet,
|
|
73
|
+
to: delegateeWallet,
|
|
74
|
+
privileges: privileges,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
console.log('Delegation successful!');
|
|
78
|
+
console.log('Transaction Hash:', hash);
|
|
79
|
+
console.log('Delegate Address:', delegateAddress);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error('Error delegating permissions:', error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
grantPermission();
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## 作為受派人發送交易
|
|
89
|
+
|
|
90
|
+
一旦被委派,受派人錢包可以通過在交易參數中指定 `delegator` 的地址來發送已授權的交易。該交易由受派人簽名,但代表委派人執行,交易費用從委派人的帳戶中支付。
|
|
91
|
+
|
|
92
|
+
### 範例
|
|
93
|
+
|
|
94
|
+
```javascript Sending a transfer as a delegatee icon=logos:javascript
|
|
95
|
+
// 假設前一個範例中的 grantPermission() 函數已成功執行
|
|
96
|
+
|
|
97
|
+
// 轉帳的接收者
|
|
98
|
+
const recipientWallet = fromRandom();
|
|
99
|
+
|
|
100
|
+
async function sendDelegatedTransaction() {
|
|
101
|
+
try {
|
|
102
|
+
const hash = await client.transfer({
|
|
103
|
+
to: recipientWallet.address,
|
|
104
|
+
token: 1, // 轉移 1 單位的鏈原生代幣
|
|
105
|
+
wallet: delegateeWallet, // 由受派人簽名
|
|
106
|
+
delegator: delegatorWallet.address, // 代表委派人執行
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
console.log('Delegated transfer successful!');
|
|
110
|
+
console.log('Transaction Hash:', hash);
|
|
111
|
+
console.log(`Check transaction at: https://beta.abtnetwork.io/explorer/txs/${hash}`);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error('Error sending delegated transaction:', error);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 確保在鏈上確認委派後再調用此函數。
|
|
118
|
+
// sendDelegatedTransaction();
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## 撤銷委派
|
|
122
|
+
|
|
123
|
+
委派人可以隨時使用 `revokeDelegate` 方法撤銷任何已授予的權限。您需要為指定的受派人指定要撤銷哪些交易類型。
|
|
124
|
+
|
|
125
|
+
### 參數
|
|
126
|
+
|
|
127
|
+
<x-field-group>
|
|
128
|
+
<x-field data-name="from" data-type="WalletObject" data-required="true">
|
|
129
|
+
<x-field-desc markdown>最初授予權限的委派人的錢包物件。</x-field-desc>
|
|
130
|
+
</x-field>
|
|
131
|
+
<x-field data-name="to" data-type="WalletObject" data-required="true">
|
|
132
|
+
<x-field-desc markdown>其權限正在被撤銷的受派人的錢包物件。</x-field-desc>
|
|
133
|
+
</x-field>
|
|
134
|
+
<x-field data-name="privileges" data-type="Array<string>" data-required="true">
|
|
135
|
+
<x-field-desc markdown>要撤銷的交易 `typeUrl` 字串陣列。</x-field-desc>
|
|
136
|
+
</x-field>
|
|
137
|
+
</x-field-group>
|
|
138
|
+
|
|
139
|
+
### 返回值
|
|
140
|
+
|
|
141
|
+
<x-field data-name="hash" data-type="Promise<string>" data-desc="一個解析為撤銷交易雜湊的 Promise。"></x-field>
|
|
142
|
+
|
|
143
|
+
### 範例
|
|
144
|
+
|
|
145
|
+
```javascript Revoking transfer permission icon=logos:javascript
|
|
146
|
+
// 假設使用與前述範例相同的 delegatorWallet 和 delegateeWallet
|
|
147
|
+
|
|
148
|
+
async function revokePermission() {
|
|
149
|
+
try {
|
|
150
|
+
const hash = await client.revokeDelegate({
|
|
151
|
+
from: delegatorWallet,
|
|
152
|
+
to: delegateeWallet,
|
|
153
|
+
privileges: [typeUrls.TransferV2Tx], // 要撤銷的權限列表
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
console.log('Revocation successful!');
|
|
157
|
+
console.log('Transaction Hash:', hash);
|
|
158
|
+
console.log(`Check transaction at: https://beta.abtnetwork.io/explorer/txs/${hash}`);
|
|
159
|
+
} catch (error) {
|
|
160
|
+
console.error('Error revoking delegation:', error);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// revokePermission();
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
此交易確認後,`delegateeWallet` 將無法再代表 `delegatorWallet` 發送 `transfer` 交易。
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# 委托权限
|
|
2
|
+
|
|
3
|
+
委托权限是一项强大的功能,它允许一个账户(委托人)授权另一个账户(被委托人)代表其发送特定类型的交易。这对于需要为用户执行操作但又不想直接访问用户主私钥的应用程序尤其有用。例如,您可以将权限委托给特定于应用程序的密钥,以转移某些资产或与智能合约交互,通过限制该密钥的权限范围来增强安全性。
|
|
4
|
+
|
|
5
|
+
本指南将引导您完成授予、使用和撤销委托权限的过程。
|
|
6
|
+
|
|
7
|
+
## 授予委托
|
|
8
|
+
|
|
9
|
+
要授权另一个账户,您可以使用 `delegate` 方法。您必须指定要委托给谁以及他们被允许发送哪些特定的交易类型。每个权限还可以有限制,例如可以涉及哪些代币或资产。
|
|
10
|
+
|
|
11
|
+
### 参数
|
|
12
|
+
|
|
13
|
+
<x-field-group>
|
|
14
|
+
<x-field data-name="from" data-type="WalletObject" data-required="true">
|
|
15
|
+
<x-field-desc markdown>委托人(授予权限的账户)的钱包对象。</x-field-desc>
|
|
16
|
+
</x-field>
|
|
17
|
+
<x-field data-name="to" data-type="WalletObject" data-required="true">
|
|
18
|
+
<x-field-desc markdown>被委托人(接收权限的账户)的钱包对象。</x-field-desc>
|
|
19
|
+
</x-field>
|
|
20
|
+
<x-field data-name="privileges" data-type="Array<object>" data-required="true">
|
|
21
|
+
<x-field-desc markdown>要授予的权限对象数组。每个对象定义一个特定的授权。</x-field-desc>
|
|
22
|
+
<x-field data-name="typeUrl" data-type="string" data-required="true">
|
|
23
|
+
<x-field-desc markdown>被许可的交易的类型 URL(例如,`fg:t:transfer_v2`)。</x-field-desc>
|
|
24
|
+
</x-field>
|
|
25
|
+
<x-field data-name="limit" data-type="object" data-required="false">
|
|
26
|
+
<x-field-desc markdown>对权限的可选限制,例如限制于特定的代币或资产。</x-field-desc>
|
|
27
|
+
<x-field data-name="tokens" data-type="Array<string>" data-required="false" data-desc="此权限适用的代币地址数组。"></x-field>
|
|
28
|
+
<x-field data-name="assets" data-type="Array<string>" data-required="false" data-desc="此权限适用的资产地址数组。"></x-field>
|
|
29
|
+
</x-field>
|
|
30
|
+
</x-field>
|
|
31
|
+
</x-field-group>
|
|
32
|
+
|
|
33
|
+
### 返回值
|
|
34
|
+
|
|
35
|
+
<x-field data-name="result" data-type="Promise<[string, string]>" data-desc="一个 Promise,它解析为一个包含交易哈希和新创建的委托地址的数组。"></x-field>
|
|
36
|
+
|
|
37
|
+
### 示例
|
|
38
|
+
|
|
39
|
+
以下是如何将 `transfer` 权限从一个账户委托给另一个账户。
|
|
40
|
+
|
|
41
|
+
```javascript Granting transfer permission icon=logos:javascript
|
|
42
|
+
import Client from '@ocap/client';
|
|
43
|
+
import { fromRandom } from '@ocap/wallet';
|
|
44
|
+
import { typeUrls } from '@ocap/proto';
|
|
45
|
+
|
|
46
|
+
const client = new Client('https://beta.abtnetwork.io/api');
|
|
47
|
+
|
|
48
|
+
// 授予权限的账户
|
|
49
|
+
const delegatorWallet = fromRandom();
|
|
50
|
+
|
|
51
|
+
// 接收权限的账户
|
|
52
|
+
const delegateeWallet = fromRandom();
|
|
53
|
+
|
|
54
|
+
async function grantPermission() {
|
|
55
|
+
try {
|
|
56
|
+
// 首先,确保委托人账户有资金。
|
|
57
|
+
// 在实际应用中,您需要从水龙头或其他账户向 delegatorWallet.address 转账。
|
|
58
|
+
console.log(`Delegator address: ${delegatorWallet.address}`);
|
|
59
|
+
console.log(`Delegatee address: ${delegateeWallet.address}`);
|
|
60
|
+
console.log('Please fund the delegator account before proceeding.');
|
|
61
|
+
|
|
62
|
+
const privileges = [
|
|
63
|
+
{
|
|
64
|
+
typeUrl: typeUrls.TransferV2Tx,
|
|
65
|
+
// 未指定限制,允许转移任何代币/资产
|
|
66
|
+
limit: { tokens: [], assets: [] },
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
const [hash, delegateAddress] = await client.delegate({
|
|
71
|
+
from: delegatorWallet,
|
|
72
|
+
to: delegateeWallet,
|
|
73
|
+
privileges: privileges,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
console.log('Delegation successful!');
|
|
77
|
+
console.log('Transaction Hash:', hash);
|
|
78
|
+
console.log('Delegate Address:', delegateAddress);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
console.error('Error delegating permissions:', error);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
grantPermission();
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## 作为被委托人发送交易
|
|
88
|
+
|
|
89
|
+
一旦被委托,被委托人钱包可以通过在交易参数中指定 `delegator` 的地址来发送已授权的交易。该交易由被委托人签名,但代表委托人执行,并且交易费用从委托人的账户中支付。
|
|
90
|
+
|
|
91
|
+
### 示例
|
|
92
|
+
|
|
93
|
+
```javascript Sending a transfer as a delegatee icon=logos:javascript
|
|
94
|
+
// 假设前一个示例中的 grantPermission() 函数已成功执行
|
|
95
|
+
|
|
96
|
+
// 转账的接收方
|
|
97
|
+
const recipientWallet = fromRandom();
|
|
98
|
+
|
|
99
|
+
async function sendDelegatedTransaction() {
|
|
100
|
+
try {
|
|
101
|
+
const hash = await client.transfer({
|
|
102
|
+
to: recipientWallet.address,
|
|
103
|
+
token: 1, // 转移 1 个链的原生代币
|
|
104
|
+
wallet: delegateeWallet, // 由被委托人签名
|
|
105
|
+
delegator: delegatorWallet.address, // 代表委托人执行
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
console.log('Delegated transfer successful!');
|
|
109
|
+
console.log('Transaction Hash:', hash);
|
|
110
|
+
console.log(`Check transaction at: https://beta.abtnetwork.io/explorer/txs/${hash}`);
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.error('Error sending delegated transaction:', error);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// 确保在链上确认委托后再调用此函数。
|
|
117
|
+
// sendDelegatedTransaction();
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## 撤销委托
|
|
121
|
+
|
|
122
|
+
委托人可以随时使用 `revokeDelegate` 方法撤销任何已授予的权限。您需要为给定的被委托人指定要撤销的交易类型。
|
|
123
|
+
|
|
124
|
+
### 参数
|
|
125
|
+
|
|
126
|
+
<x-field-group>
|
|
127
|
+
<x-field data-name="from" data-type="WalletObject" data-required="true">
|
|
128
|
+
<x-field-desc markdown>最初授予权限的委托人的钱包对象。</x-field-desc>
|
|
129
|
+
</x-field>
|
|
130
|
+
<x-field data-name="to" data-type="WalletObject" data-required="true">
|
|
131
|
+
<x-field-desc markdown>其权限被撤销的被委托人的钱包对象。</x-field-desc>
|
|
132
|
+
</x-field>
|
|
133
|
+
<x-field data-name="privileges" data-type="Array<string>" data-required="true">
|
|
134
|
+
<x-field-desc markdown>要撤销的交易 `typeUrl` 字符串数组。</x-field-desc>
|
|
135
|
+
</x-field>
|
|
136
|
+
</x-field-group>
|
|
137
|
+
|
|
138
|
+
### 返回值
|
|
139
|
+
|
|
140
|
+
<x-field data-name="hash" data-type="Promise<string>" data-desc="一个 Promise,它解析为撤销操作的交易哈希。"></x-field>
|
|
141
|
+
|
|
142
|
+
### 示例
|
|
143
|
+
|
|
144
|
+
```javascript Revoking transfer permission icon=logos:javascript
|
|
145
|
+
// 假设使用与前面示例相同的 delegatorWallet 和 delegateeWallet
|
|
146
|
+
|
|
147
|
+
async function revokePermission() {
|
|
148
|
+
try {
|
|
149
|
+
const hash = await client.revokeDelegate({
|
|
150
|
+
from: delegatorWallet,
|
|
151
|
+
to: delegateeWallet,
|
|
152
|
+
privileges: [typeUrls.TransferV2Tx], // 要撤销的权限列表
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
console.log('Revocation successful!');
|
|
156
|
+
console.log('Transaction Hash:', hash);
|
|
157
|
+
console.log(`Check transaction at: https://beta.abtnetwork.io/explorer/txs/${hash}`);
|
|
158
|
+
} catch (error) {
|
|
159
|
+
console.error('Error revoking delegation:', error);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// revokePermission();
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
此交易确认后,`delegateeWallet` 将无法再代表 `delegatorWallet` 发送 `transfer` 交易。
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# アカウントの管理
|
|
2
|
+
|
|
3
|
+
OCAP を利用したブロックチェーンでは、アカウントは基本的にアドレスに関連付けられた状態であり、暗号鍵のペア(公開鍵と秘密鍵)によって制御されます。理解すべき重要な概念は、アカウントが暗黙的に作成されるということです。アカウントは、トークンや資産の転送など、最初の受信トランザクションを受け取るとすぐに、チェーン上で公式に存在します。明示的な `createAccount` トランザクションはありません。
|
|
4
|
+
|
|
5
|
+
このガイドでは、重要なアカウント管理操作である、アカウントを新しい鍵セットに移行する方法に焦点を当てます。これは、アドレス、残高、または資産を変更することなく、アカウントの所有権を変更できる重要なセキュリティ機能です。
|
|
6
|
+
|
|
7
|
+
## アカウントを新しい鍵に移行する
|
|
8
|
+
|
|
9
|
+
`migrateAccount` 関数を使用すると、既存のアカウントアドレスを新しい公開鍵に関連付けることができます。これは、次のような複数のシナリオで役立ちます。
|
|
10
|
+
|
|
11
|
+
- **鍵の侵害**:秘密鍵が漏洩した疑いがある場合、アカウントを新しい安全な鍵ペアに移行して、不正アクセスを防ぐことができます。
|
|
12
|
+
- **セキュリティのアップグレード**:古いタイプの鍵から、より新しく安全な鍵に移行したい場合があります。
|
|
13
|
+
|
|
14
|
+
この操作により、ブロックチェーン上の履歴と状態を保持しながら、アカウントの制御を効果的に移転できます。
|
|
15
|
+
|
|
16
|
+
### パラメーター
|
|
17
|
+
|
|
18
|
+
<x-field-group>
|
|
19
|
+
<x-field data-name="from" data-type="WalletObject" data-required="true">
|
|
20
|
+
<x-field-desc markdown>移行される現在のアカウントを表すウォレットオブジェクト。このウォレットは、所有権を証明するためにトランザクションに署名する必要があります。</x-field-desc>
|
|
21
|
+
</x-field>
|
|
22
|
+
<x-field data-name="to" data-type="WalletObject" data-required="true">
|
|
23
|
+
<x-field-desc markdown>制御が移転される新しいウォレットオブジェクト。このウォレットの公開鍵が、アカウントアドレスの新しい権限になります。</x-field-desc>
|
|
24
|
+
</x-field>
|
|
25
|
+
</x-field-group>
|
|
26
|
+
|
|
27
|
+
### 戻り値
|
|
28
|
+
|
|
29
|
+
`migrateAccount` メソッドは、トランザクションハッシュを文字列として解決する Promise を返します。
|
|
30
|
+
|
|
31
|
+
### 例
|
|
32
|
+
|
|
33
|
+
古いウォレットから新しいウォレットにアカウントを移行する方法を次に示します。
|
|
34
|
+
|
|
35
|
+
```javascript Migrating an Account icon=logos:javascript
|
|
36
|
+
import Client from '@ocap/client';
|
|
37
|
+
import { fromRandom } from '@ocap/wallet';
|
|
38
|
+
|
|
39
|
+
const client = new Client('https://beta.abtnetwork.io/api');
|
|
40
|
+
|
|
41
|
+
// oldWallet がアカウントの現在承認されているウォレットであると仮定します
|
|
42
|
+
const oldWallet = fromRandom();
|
|
43
|
+
|
|
44
|
+
// 新しい鍵セットで新しいウォレットを作成します
|
|
45
|
+
const newWallet = fromRandom();
|
|
46
|
+
|
|
47
|
+
async function migrate() {
|
|
48
|
+
try {
|
|
49
|
+
// 移行する前に、通常は oldWallet のアドレスに資金を供給します。
|
|
50
|
+
// この例では、トランザクション手数料を支払うのに十分な資金があると仮定します。
|
|
51
|
+
// テストトークンは https://faucet.abtnetwork.io/ から入手できます
|
|
52
|
+
console.log(`アカウントを ${oldWallet.address} から ${newWallet.address} に関連付けられた新しい鍵に移行しています`);
|
|
53
|
+
|
|
54
|
+
const hash = await client.migrateAccount({
|
|
55
|
+
from: oldWallet,
|
|
56
|
+
to: newWallet,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
console.log('アカウント移行トランザクションは正常に送信されました!');
|
|
60
|
+
console.log('トランザクションハッシュ:', hash);
|
|
61
|
+
console.log(`トランザクションを表示: https://beta.abtnetwork.io/explorer/txs/${hash}`);
|
|
62
|
+
|
|
63
|
+
} catch (err) {
|
|
64
|
+
console.error('アカウント移行エラー:', err);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
migrate();
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
鍵を移行してアカウントを保護する方法がわかったので、プライマリキーを共有せずに他のアカウントに限定的な権限を付与する方法を学びたいと思うかもしれません。詳細については、[権限の委任](./how-to-guides-delegate-permissions.md) ガイドを参照してください。
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Manage Accounts
|
|
2
|
+
|
|
3
|
+
On an OCAP-powered blockchain, an account is fundamentally a state associated with an address, controlled by a pair of cryptographic keys (a public key and a private key). A key concept to understand is that accounts are created implicitly. An account officially exists on-chain as soon as it receives its first incoming transaction, such as a token or asset transfer. There is no explicit `createAccount` transaction.
|
|
4
|
+
|
|
5
|
+
This guide focuses on a critical account management operation: migrating an account to a new set of keys. This is an essential security feature that allows you to change the ownership of an account without altering its address, balance, or assets.
|
|
6
|
+
|
|
7
|
+
## Migrate an Account to New Keys
|
|
8
|
+
|
|
9
|
+
The `migrateAccount` function allows you to associate an existing account address with a new public key. This is useful in several scenarios, such as:
|
|
10
|
+
|
|
11
|
+
- **Key Compromise**: If you suspect your private key has been exposed, you can migrate the account to a new, secure key pair to prevent unauthorized access.
|
|
12
|
+
- **Upgrading Security**: You might want to migrate from an older key type to a newer, more secure one.
|
|
13
|
+
|
|
14
|
+
This operation effectively transfers control of the account while preserving its history and state on the blockchain.
|
|
15
|
+
|
|
16
|
+
### Parameters
|
|
17
|
+
|
|
18
|
+
<x-field-group>
|
|
19
|
+
<x-field data-name="from" data-type="WalletObject" data-required="true">
|
|
20
|
+
<x-field-desc markdown>The wallet object representing the current account that is being migrated. This wallet must sign the transaction to prove ownership.</x-field-desc>
|
|
21
|
+
</x-field>
|
|
22
|
+
<x-field data-name="to" data-type="WalletObject" data-required="true">
|
|
23
|
+
<x-field-desc markdown>The new wallet object to which control will be transferred. The public key from this wallet will become the new authority for the account address.</x-field-desc>
|
|
24
|
+
</x-field>
|
|
25
|
+
</x-field-group>
|
|
26
|
+
|
|
27
|
+
### Returns
|
|
28
|
+
|
|
29
|
+
The `migrateAccount` method returns a Promise that resolves to the transaction hash as a string.
|
|
30
|
+
|
|
31
|
+
### Example
|
|
32
|
+
|
|
33
|
+
Here's how to migrate an account from an old wallet to a new one.
|
|
34
|
+
|
|
35
|
+
```javascript Migrating an Account icon=logos:javascript
|
|
36
|
+
import Client from '@ocap/client';
|
|
37
|
+
import { fromRandom } from '@ocap/wallet';
|
|
38
|
+
|
|
39
|
+
const client = new Client('https://beta.abtnetwork.io/api');
|
|
40
|
+
|
|
41
|
+
// Assume oldWallet is the currently authorized wallet for the account
|
|
42
|
+
const oldWallet = fromRandom();
|
|
43
|
+
|
|
44
|
+
// Create a new wallet with a new set of keys
|
|
45
|
+
const newWallet = fromRandom();
|
|
46
|
+
|
|
47
|
+
async function migrate() {
|
|
48
|
+
try {
|
|
49
|
+
// Before migrating, you would typically fund the oldWallet's address.
|
|
50
|
+
// For this example, we'll assume it has enough funds to pay for the transaction fee.
|
|
51
|
+
// You can get test tokens from https://faucet.abtnetwork.io/
|
|
52
|
+
console.log(`Migrating account from ${oldWallet.address} to new keys associated with ${newWallet.address}`);
|
|
53
|
+
|
|
54
|
+
const hash = await client.migrateAccount({
|
|
55
|
+
from: oldWallet,
|
|
56
|
+
to: newWallet,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
console.log('Account migration transaction sent successfully!');
|
|
60
|
+
console.log('Transaction Hash:', hash);
|
|
61
|
+
console.log(`View transaction at: https://beta.abtnetwork.io/explorer/txs/${hash}`);
|
|
62
|
+
|
|
63
|
+
} catch (err) {
|
|
64
|
+
console.error('Error migrating account:', err);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
migrate();
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
Now that you know how to secure your account by migrating keys, you might want to learn how to grant limited permissions to other accounts without sharing your primary keys. See the [Delegate Permissions](./how-to-guides-delegate-permissions.md) guide for more details.
|