viz-js-lib 0.18.2 → 0.18.3
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 +47 -0
- package/api-frontend/app.js +5 -1
- package/dist/statistics.html +1 -1
- package/dist/viz-tests.min.js.gz +0 -0
- package/dist/viz.min.js.gz +0 -0
- package/lib/agent.js +237 -0
- package/lib/index.js +2 -0
- package/package.json +1 -1
- package/test/agent.test.js +199 -0
- package/test/methods_by_version.js +2 -0
package/README.md
CHANGED
|
@@ -70,6 +70,53 @@ viz.api.getAccounts(['ned', 'dan'], function(err, result) {
|
|
|
70
70
|
});
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
+
### Key checks: authority or agent (HF15)
|
|
74
|
+
|
|
75
|
+
HF15 added `set_agent_permission` (op 105): a principal may hand a key an explicit, frozen list of
|
|
76
|
+
its operations — an *agent*. An agent is not an account and never appears in any authority, so the
|
|
77
|
+
old check ("`getAccount` and look at `active_authority.key_auths`") silently rejects agent keys.
|
|
78
|
+
The recipe is now **authority OR agents**, and `viz.agent.check()` does both in one call.
|
|
79
|
+
|
|
80
|
+
Rules the helper mirrors from the node (`agent_evaluator.cpp::usable_agent_row`):
|
|
81
|
+
|
|
82
|
+
- an agent answers direct active/regular requirements only, and only for operations on its list —
|
|
83
|
+
the master authority is never satisfied by an agent, nor is a nested/other authority;
|
|
84
|
+
- `expiration` epoch (`1970-01-01T00:00:00`) = perpetual; a date in the past = revoked;
|
|
85
|
+
- empty `operations` and `addons` = revoked; `addons` are off-chain scopes the node stores and
|
|
86
|
+
never interprets, so a service matches its own scope there;
|
|
87
|
+
- one key belongs to one agent of a principal; a change of master/active, a recovery or a sale
|
|
88
|
+
wipes every agent of the principal.
|
|
89
|
+
|
|
90
|
+
`check(account, key, operation)` resolves to `{allowed, source: 'authority'|'agent'|'none', role,
|
|
91
|
+
agent, operation}`; `find()` resolves to the raw row (or `false`), `has()` to a bool. Pass the wire
|
|
92
|
+
operation name (`transfer`, `pm_place_bet`, ...) to check a specific operation — with no operation
|
|
93
|
+
an agent key is only answered as "this is a live agent key", because its grants are per-operation.
|
|
94
|
+
A key that is only in a nested authority (`account_auths`) is not resolved here: use
|
|
95
|
+
`verify_authority` with a signed transaction for the full recursive check. On a node without HF15
|
|
96
|
+
the agent call fails, `find()` reads that as "no agents", and the check degrades to authorities
|
|
97
|
+
only.
|
|
98
|
+
|
|
99
|
+
`poisoned(row)` and `addonMatches(row, scope)` are the two pure row predicates the verdicts are
|
|
100
|
+
built from, exported for callers that already hold a row (and mirrored by `VIZ\Agent` in the PHP
|
|
101
|
+
lib).
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
viz.config.set('websocket', 'https://api.viz.world/');
|
|
105
|
+
|
|
106
|
+
//the key recovered from the request signature
|
|
107
|
+
viz.agent.check('altbettor', 'VIZ7iiYUk6hFuieveBJcTVTV33aNuC2vZauXuYc9Hki3moxsm9WXe', 'transfer')
|
|
108
|
+
.then(verdict => {
|
|
109
|
+
if (verdict.allowed) console.log('allowed by', verdict.source);//'authority' or 'agent'
|
|
110
|
+
else console.log('denied');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
viz.agent.get('altbettor').then(rows => console.log(rows));//every agent of the principal
|
|
114
|
+
viz.agent.find('altbettor', 'VIZ7ii...').then(row => console.log(row));//live row, or false
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The write side is `viz.broadcast.setAgentPermission(...)`. The raw read method is
|
|
118
|
+
`viz.api.getAgentPermissionsAsync(account)`.
|
|
119
|
+
|
|
73
120
|
## Contributions
|
|
74
121
|
Patches are welcome! Contributors are listed in the package.json file. Please run the tests before opening a pull request and make sure that you are passing all of them. If you would like to contribute, but don't know what to work on, check the issues list.
|
|
75
122
|
|
package/api-frontend/app.js
CHANGED
|
@@ -43,6 +43,8 @@ const METHODS = [
|
|
|
43
43
|
{api:"database_api",method:"get_accounts_on_auction",params:["from","limit","name_prefix"]},
|
|
44
44
|
{api:"database_api",method:"get_subaccounts_on_sale",params:["from","limit","name_prefix"]},
|
|
45
45
|
{api:"database_api",method:"get_agent_permissions",params:["account"]},
|
|
46
|
+
{api:"database_api",method:"get_key_history",params:["account","from","limit"]},
|
|
47
|
+
{api:"database_api",method:"get_key_history_by_key",params:["key","limit"]},
|
|
46
48
|
{api:"account_by_key",method:"get_key_references",params:["account_name_type"]},
|
|
47
49
|
{api:"network_broadcast_api",method:"broadcast_transaction",params:["trx"]},
|
|
48
50
|
{api:"network_broadcast_api",method:"broadcast_transaction_with_callback",params:["confirmationCallback","trx"]},
|
|
@@ -422,7 +424,9 @@ const SPEC = {
|
|
|
422
424
|
get_accounts_on_sale: {d:"Returns accounts currently on sale (direct sale, not auction).",p:{from:{c:"From Offset",d:"Number of results to skip for pagination."},limit:{c:"Limit",d:"Maximum number of results (max 1000)."},name_prefix:{c:"Name Prefix",d:"Optional. Only accounts whose name starts with this prefix. Matched against the account-name index, so it searches the whole set and finds accounts past the first page. Empty or omitted returns all."}}},
|
|
423
425
|
get_accounts_on_auction: {d:"Returns accounts currently on auction (no target buyer set).",p:{from:{c:"From Offset",d:"Number of results to skip for pagination."},limit:{c:"Limit",d:"Maximum number of results (max 1000)."},name_prefix:{c:"Name Prefix",d:"Optional. Only accounts whose name starts with this prefix. Matched against the account-name index, so it searches the whole set and finds accounts past the first page. Empty or omitted returns all."}}},
|
|
424
426
|
get_subaccounts_on_sale: {d:"Returns subaccounts currently on sale.",p:{from:{c:"From Offset",d:"Number of results to skip for pagination."},limit:{c:"Limit",d:"Maximum number of results (max 1000)."},name_prefix:{c:"Name Prefix",d:"Optional. Only subaccounts whose name starts with this prefix. Matched against the account-name index, so it searches the whole set and finds subaccounts past the first page. Empty or omitted returns all."}}},
|
|
425
|
-
get_agent_permissions: {d:"Returns the agents of a principal (HF15 agent access): name, public key, allowed operations, expiration (1970-01-01T00:00:00 = perpetual), addons (off-chain scopes such as vizhub) and an expired flag. At most 16 rows, ordered by agent name. Nodes without HF15 answer with an unknown-method error.",p:{account:{c:"Account Name",d:"The principal whose agents to return."}}}
|
|
427
|
+
get_agent_permissions: {d:"Returns the agents of a principal (HF15 agent access): name, public key, allowed operations, expiration (1970-01-01T00:00:00 = perpetual), addons (off-chain scopes such as vizhub) and an expired flag. At most 16 rows, ordered by agent name. Nodes without HF15 answer with an unknown-method error.",p:{account:{c:"Account Name",d:"The principal whose agents to return."}}},
|
|
428
|
+
get_key_history: {d:"Permanent key history of an account (HF15): every key or account it stopped standing behind — role (master/active/regular/memo), key or auth_account, weight, weight_threshold, valid_until_block (last block the key still held) and valid_until_time. Oldest first; rows are never pruned. Nodes without HF15 answer with an unknown-method error.",p:{account:{c:"Account Name",d:"Whose key history to return."},from:{c:"From",d:"Row id to start at (0 = first row); for the next page pass the last id + 1."},limit:{c:"Limit",d:"Max rows, up to 1000."}}},
|
|
429
|
+
get_key_history_by_key: {d:"Who held a public key in the past and until which block (HF15 key history). Keys currently in use are not listed — they are in the accounts themselves.",p:{key:{c:"Public Key",d:"The key to look up (VIZ...)."},limit:{c:"Limit",d:"Max rows, up to 1000."}}}
|
|
426
430
|
},
|
|
427
431
|
account_by_key: {
|
|
428
432
|
get_key_references: {d:"Returns all account names that reference the given public keys in their authority.",p:{account_name_type:{c:"Public Keys",d:"Array of public keys to look up.",t:"array"}}}
|