@verii/contract-permissions 1.0.0-pre.1752076816
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/LICENSE +202 -0
- package/NOTICE +1 -0
- package/README.md +30 -0
- package/index.js +24 -0
- package/package.json +32 -0
- package/src/constants.js +10 -0
- package/src/contracts/permissions.json +17969 -0
- package/src/permissions.js +148 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023 Velocity Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const { initContractClient } = require('@verii/base-contract-io');
|
|
18
|
+
|
|
19
|
+
const contractAbi = require('./contracts/permissions.json');
|
|
20
|
+
|
|
21
|
+
const initPermissions = async (
|
|
22
|
+
{ privateKey, contractAddress, rpcProvider },
|
|
23
|
+
context
|
|
24
|
+
) => {
|
|
25
|
+
const { log } = context;
|
|
26
|
+
log.info({ func: 'initPermission', privateKey, contractAddress });
|
|
27
|
+
|
|
28
|
+
const { contractClient } = await initContractClient(
|
|
29
|
+
{
|
|
30
|
+
privateKey,
|
|
31
|
+
contractAddress,
|
|
32
|
+
rpcProvider,
|
|
33
|
+
contractAbi,
|
|
34
|
+
},
|
|
35
|
+
context
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const updateAddressScopes = async ({
|
|
39
|
+
address,
|
|
40
|
+
scopesToAdd = [],
|
|
41
|
+
scopesToRemove = [],
|
|
42
|
+
}) => {
|
|
43
|
+
log.info({
|
|
44
|
+
func: 'updateAddressScopes',
|
|
45
|
+
address,
|
|
46
|
+
scopesToAdd,
|
|
47
|
+
scopesToRemove,
|
|
48
|
+
});
|
|
49
|
+
const tx = await contractClient.updateAddressScopes(
|
|
50
|
+
address,
|
|
51
|
+
scopesToAdd,
|
|
52
|
+
scopesToRemove
|
|
53
|
+
);
|
|
54
|
+
await tx.wait();
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const addAddressScope = async ({ address, scope }) => {
|
|
58
|
+
log.info({ func: 'addAddressScope', address, scope });
|
|
59
|
+
const tx = await contractClient.addAddressScope(address, scope);
|
|
60
|
+
await tx.wait();
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const removeAddressScope = async ({ address, scope }) => {
|
|
64
|
+
log.info({ func: 'removeAddressScope', address, scope });
|
|
65
|
+
const tx = await contractClient.removeAddressScope(address, scope);
|
|
66
|
+
await tx.wait();
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const getPrimaries = async () => {
|
|
70
|
+
log.info({ func: 'getPrimaries' });
|
|
71
|
+
return contractClient.getPrimaries();
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const addPrimary = async ({ primary, permissioning, rotation }) => {
|
|
75
|
+
log.info({ func: 'addPrimary', primary, permissioning, rotation });
|
|
76
|
+
const tx = await contractClient.addPrimary(
|
|
77
|
+
primary,
|
|
78
|
+
permissioning,
|
|
79
|
+
rotation
|
|
80
|
+
);
|
|
81
|
+
await tx.wait();
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const removeOperatorKey = async ({ primary, operator }) => {
|
|
85
|
+
log.info({ func: 'removeOperator', primary, operator });
|
|
86
|
+
const tx = await contractClient.removeOperatorKey(primary, operator);
|
|
87
|
+
await tx.wait();
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const addOperatorKey = async ({ primary, operator }) => {
|
|
91
|
+
log.info({ func: 'addOperatorKey', primary, operator });
|
|
92
|
+
const tx = await contractClient.addOperatorKey(primary, operator);
|
|
93
|
+
await tx.wait();
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const rotateOperatorKey = async ({ primary, newOperator, oldOperator }) => {
|
|
97
|
+
log.info({ func: 'rotateOperatorKey', primary, newOperator, oldOperator });
|
|
98
|
+
const tx = await contractClient.rotateOperatorKey(
|
|
99
|
+
primary,
|
|
100
|
+
newOperator,
|
|
101
|
+
oldOperator
|
|
102
|
+
);
|
|
103
|
+
await tx.wait();
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const rotatePermissioning = async ({
|
|
107
|
+
primary,
|
|
108
|
+
newPermissioning,
|
|
109
|
+
newRotation,
|
|
110
|
+
}) => {
|
|
111
|
+
log.info({
|
|
112
|
+
func: 'rotatePermissioning',
|
|
113
|
+
primary,
|
|
114
|
+
newPermissioning,
|
|
115
|
+
newRotation,
|
|
116
|
+
});
|
|
117
|
+
const tx = await contractClient.rotatePermissioning(
|
|
118
|
+
primary,
|
|
119
|
+
newPermissioning,
|
|
120
|
+
newRotation
|
|
121
|
+
);
|
|
122
|
+
await tx.wait();
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const lookupPrimary = async (address) => {
|
|
126
|
+
log.info({
|
|
127
|
+
func: 'lookupPrimary',
|
|
128
|
+
address,
|
|
129
|
+
});
|
|
130
|
+
return contractClient.lookupPrimary(address);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
contractClient,
|
|
135
|
+
getPrimaries,
|
|
136
|
+
addAddressScope,
|
|
137
|
+
addOperatorKey,
|
|
138
|
+
addPrimary,
|
|
139
|
+
removeOperatorKey,
|
|
140
|
+
removeAddressScope,
|
|
141
|
+
rotateOperatorKey,
|
|
142
|
+
rotatePermissioning,
|
|
143
|
+
lookupPrimary,
|
|
144
|
+
updateAddressScopes,
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
module.exports = initPermissions;
|