diff --git a/.gitbook/SUMMARY.md b/.gitbook/SUMMARY.md index 0e9265f64..034616226 100644 --- a/.gitbook/SUMMARY.md +++ b/.gitbook/SUMMARY.md @@ -50,6 +50,7 @@ * [Insurance Funds](querying/querying-chain/querying-chain-insurance-funds.md) * [Oracle](querying/querying-chain/querying-chain-oracle.md) * [Peggy](querying/querying-chain/querying-chain-peggy.md) + * [Permissions](querying/querying-chain/querying-chain-permissions.md) * [Staking](querying/querying-chain/querying-chain-staking.md) * [Tendermint](querying/querying-chain/querying-chain-tendermint.md) * [Wasm](querying/querying-chain/querying-chain-wasm.md) @@ -75,6 +76,7 @@ * [IBC](core-modules/ibc.md) * [Insurance](core-modules/insurance.md) * [Peggy](core-modules/peggy.md) + * [Permissions](core-modules/permissions.md) * [Staking](core-modules/staking.md) * [Tokenfactory](core-modules/token-factory.md) * [Wasm](core-modules/wasm.md) diff --git a/.gitbook/core-modules/README.md b/.gitbook/core-modules/README.md index 737d88611..eaa7defdc 100644 --- a/.gitbook/core-modules/README.md +++ b/.gitbook/core-modules/README.md @@ -16,6 +16,7 @@ Within this section, we are going to explore the core modules of the Injective c | [IBC](ibc.md) | Used for cross-Cosmos chain transfers | | [Insurance](insurance.md) | Used for on-chain insurance funds | | [Peggy](peggy.md) | Used for the Injective <> Ethereum Bridge | +| [Permissions](permissions.md) | Used fot on-chain permissions | [Staking](staking.md) | Used for on-chain staking | | [Tokenfactory](token-factory.md) | Used for creating and managing `tokenfactory` tokens | | [Wasm](wasm.md) | Used for interacting with the Cosmwasm Layer | diff --git a/.gitbook/core-modules/permissions.md b/.gitbook/core-modules/permissions.md new file mode 100644 index 000000000..acccaebc4 --- /dev/null +++ b/.gitbook/core-modules/permissions.md @@ -0,0 +1,246 @@ +# Permissions Module + +The Permissions Module facilitates the management of namespaces, roles, and permissions within the Injective ecosystem. This documentation outlines the key message types and their usage for interacting with permissions-related data. + +### Messages + +Let's explore (and provide examples) the Messages that the Permissions module exports and we can use to interact with the Injective chain. + +### `MsgClaimVoucher` + +This message is used to claim a voucher tied to a specific address within a namespace. + +```ts +import { + MsgClaimVoucher, + MsgBroadcasterWithPk, +} from "@injectivelabs/sdk-ts"; +import { Network } from "@injectivelabs/networks"; + +const injectiveAddress = "inj1..."; +const privateKey = "0x..."; +const denom = "inj"; + +const msg = MsgClaimVoucher.fromJSON({ + injectiveAddress, + denom, +}); + +const txHash = await new MsgBroadcasterWithPk({ + privateKey, + network: Network.Testnet +}).broadcast({ + msgs: msg +}); + +console.log(txHash); + +``` + +### `MsgCreateNamespace` + +This message is used to creates a new namespace with permissions and roles. + +```ts +import { + MsgCreateNamespace, + MsgBroadcasterWithPk, +} from "@injectivelabs/sdk-ts"; +import { Network } from "@injectivelabs/networks"; + +const injectiveAddress = "inj1..."; +const secondAddress = "inj2....."; +const privateKey = "0x..."; +const denom = "inj"; +const wasmHook = "inj3...."; +const mintsPausedValue = false; +const sendsPausedValue = false; +const burnsPausedValue = false; +const role1 = "Everyone"; +const permissions1 = 1; + +const msg = MsgCreateNamespace.fromJSON({ + injectiveAddress, + namespace: { + denom, + wasmHook, + mintsPausedValue, + sendsPausedValue, + burnsPausedValue, + rolePermissions: { + role: role1, + permissions: permissions1, + }, + addressRoles: { + address: injectiveAddress, + roles: [role1], + }, + }, +}) + + +const txHash = await new MsgBroadcasterWithPk({ + privateKey, + network: Network.Testnet +}).broadcast({ + msgs: msg +}); + +console.log(txHash); + +``` + +### `MsgDeleteNamespace` + +This message is used to delete an existing namespace. + +```ts +import { + MsgDeleteNamespace, + MsgBroadcasterWithPk, +} from "@injectivelabs/sdk-ts"; +import { Network } from "@injectivelabs/networks"; + +const injectiveAddress = "inj1..."; +const privateKey = "0x..."; +const denom = "inj"; + +const msg = MsgDeleteNamespace.fromJSON({ + injectiveAddress, + denom +}); + +const txHash = await new MsgBroadcasterWithPk({ + privateKey, + network: Network.Testnet +}).broadcast({ + msgs: msg +}); + +console.log(txHash); + +``` + +### `MsgRevokeNamespaceRoles` + +This message is used to revoke roles from specified addresses in a namespace. + +```ts +import { + MsgRevokeNamespaceRoles, + MsgBroadcasterWithPk, +} from "@injectivelabs/sdk-ts"; +import { Network } from "@injectivelabs/networks"; + +const injectiveAddress = "inj1..."; +const privateKey = "0x..."; +const denom = "inj"; +const roles = ["role1","role2"]; + +const msg = MsgRevokeNamespaceRoles.fromJSON({ + injectiveAddress, + denom, + addressRolesToRevoke: { + injectiveAddress, + roles: roles, + }, +}); + +const txHash = await new MsgBroadcasterWithPk({ + privateKey, + network: Network.Testnet +}).broadcast({ + msgs: msg +}); + +console.log(txHash); + +``` + +### `MsgUpdateNamespace` + +This message is used to update namespace properties like mints, sends, and burns. + +```ts +import { + MsgUpdateNamespace, + MsgBroadcasterWithPk, +} from "@injectivelabs/sdk-ts"; +import { Network } from "@injectivelabs/networks"; + +const injectiveAddress = "inj1..." +const privateKey = "0x..."; +const denom = "inj"; +const wasmHookValue = "inj2..."; +const mintsPausedValue = false; +const sendsPausedValue = false; +const burnsPausedValue = true; + +const msg = await new MsgUpdateNamespace.fromJSON({ + injectiveAddress, + denom, + wasmHook: { + newValue: wasmHookValue + }, + mintsPaused: { + newValue: mintsPausedValue; + }, + sendsPaused: { + newValue: sendsPausedValue; + }, + burnsPaused: { + newValue: burnsPausedValue; + }, +}); + +const txHash = await new MsgBroadcasterWithPk({ + privateKey, + network: Network.Testnet +}).broadcast({ + msgs: msg +}); + +console.log(txHash); + +``` + +### `MsgUpdateNamespaceRoles` + +This message is used to modify the roles and permissions for addresses in a namespace. + +```ts +import { + MsgUpdateNamespaceRoles, + MsgBroadcasterWithPk, +} from "@injectivelabs/sdk-ts"; +import { Network } from "@injectivelabs/networks"; + +const injectiveAddress = "inj1..."; +const privateKey = "0x..."; +const denom = "inj"; +const role = "role1"; +const permissions = 4; + +const msg = MsgUpdateNamespaceRoles.fromJSON({ + injectiveAddress, + denom, + rolePermissions: { + role, + permissions: permissions + }, + addressRoles: { + injectiveAddress, + roles: [role], + }, +}); + +const txHash = await new MsgBroadcasterWithPk({ + privateKey, + network: Network.Testnet +}).broadcast({ + msgs: msg +}); + +console.log(txHash); + +``` diff --git a/.gitbook/querying/querying-chain/README.md b/.gitbook/querying/querying-chain/README.md index 37b04f896..717ca2fba 100644 --- a/.gitbook/querying/querying-chain/README.md +++ b/.gitbook/querying/querying-chain/README.md @@ -17,6 +17,7 @@ | [Mint](querying-chain-mint.md) | Query data from the mint module | | [Oracl](querying-chain-oracle.md) | Query data related to the oracle api | | [Peggy](querying-chain-peggy.md) | Query ethereum data using the peggy api | +| [Permissions](querying-chain-permissions.md) | Query data from the permissions module | | [Staking](querying-chain-staking.md) | Query data from the staking module | | [Wasm](querying-chain-wasm.md) | Query data from the wasm module | | [WasmX](querying-chain-wasmx.md) | Query data from the wasmX module | diff --git a/.gitbook/querying/querying-chain/querying-chain-permissions.md b/.gitbook/querying/querying-chain/querying-chain-permissions.md new file mode 100644 index 000000000..ea5d9048f --- /dev/null +++ b/.gitbook/querying/querying-chain/querying-chain-permissions.md @@ -0,0 +1,98 @@ +# Permissions + +Example code snippets to query data related to the permissions module on chain. + +### Using gRPC + +#### Fetch all namespaces + +```ts +import { ChainGrpcPermissionsApi } from '@injectivelabs/sdk-ts' +import { getNetworkEndpoints, Network } from '@injectivelabs/networks' + +const endpoints = getNetworkEndpoints(Network.Testnet) +const chainGrpcPermissionsApi = new ChainGrpcPermissionsApi(endpoints.grpc) + +const allNamespaces = await chainGrpcPermissionsApi.fetchAllNamespaces() + +console.log(allNamespaces) +``` + +#### Fetch a namespace based on the denom + +```ts +import { ChainGrpcPermissionsApi } from '@injectivelabs/sdk-ts' +import { getNetworkEndpoints, Network } from '@injectivelabs/networks' + +const endpoints = getNetworkEndpoints(Network.Testnet) +const chainGrpcPermissionsApi = new ChainGrpcPermissionsApi(endpoints.grpc) + +const subdenom = 'NINJA' +const includeRoles = true + +const namespace = await chainGrpcPermissionsApi.fetchNamespaceByDenom({ + subdenom, + includeRoles: includeRoles, +}) + +console.log(namespace) +``` + +#### Fetch all roles that are associated to an address based on the denom + +```ts +import { ChainGrpcPermissionsApi } from '@injectivelabs/sdk-ts' +import { getNetworkEndpoints, Network } from '@injectivelabs/networks' + +const endpoints = getNetworkEndpoints(Network.Testnet) +const chainGrpcPermissionsApi = new ChainGrpcPermissionsApi(endpoints.grpc) + +const injectiveAddress = 'inj...' +const subdenom = 'NINJA' + +const addressRoles = await chainGrpcPermissionsApi.fetchAddressRoles({ + injectiveAddress, + denom: subdenom, +}) + +console.log(addressRoles) +``` + +#### Fetch all addresses that are associated to a given role for a denom + +```ts +import { ChainGrpcPermissionsApi } from '@injectivelabs/sdk-ts' +import { getNetworkEndpoints, Network } from '@injectivelabs/networks' + +const endpoints = getNetworkEndpoints(Network.Testnet) +const chainGrpcPermissionsApi = new ChainGrpcPermissionsApi(endpoints.grpc) + +const subdenom = 'NINJA' +const role = 'role' + + +const addressesByRole = await chainGrpcPermissionsApi.fetchAddressesByRole({ + subdenom, + role: role, +}) + +console.log(addressesByRole) +``` + +#### Fetch vouchers for a given injective address + +```ts +import { ChainGrpcPermissionsApi } from '@injectivelabs/sdk-ts' +import { getNetworkEndpoints, Network } from '@injectivelabs/networks' + +const endpoints = getNetworkEndpoints(Network.Testnet) +const chainGrpcPermissionsApi = new ChainGrpcPermissionsApi(endpoints.grpc) + +const injectiveAddress = 'inj...' + +const vouchers = await chainGrpcPermissionsApi.fetchVouchersForAddress( + injectiveAddress, +) + +console.log(vouchers) +``` diff --git a/packages/sdk-ts/src/client/chain/types/permissions.ts b/packages/sdk-ts/src/client/chain/types/permissions.ts index fece2516b..c4adbfd1d 100644 --- a/packages/sdk-ts/src/client/chain/types/permissions.ts +++ b/packages/sdk-ts/src/client/chain/types/permissions.ts @@ -1,56 +1,55 @@ import { - InjectivePermissionsV1Beta1Permissions, - InjectivePermissionsV1Beta1Params, -} from '@injectivelabs/core-proto-ts' - -import { Coin } from '@injectivelabs/ts-types' - -export interface Namespace { - denom: string - wasmHook: string - mintsPaused: boolean - sendsPaused: boolean - burnsPaused: boolean - rolePermissions: Role[] - addressRoles: AddressRoles[] -} - -export interface PermissionsModuleParams { - wasmHookQueryMaxGas: string -} - -export interface AddressRoles { - address: string - roles: string[] -} - -export interface Role { - role: string - permissions: number -} - -export interface RoleIDs { - roleIds: number[] -} - -export interface Voucher { - coins: Coin[] -} - -export interface AddressVoucher { - address: string - voucher?: Voucher -} - -export type GrpcPermissionsNamespace = - InjectivePermissionsV1Beta1Permissions.Namespace -export type GrpcPermissionsAddressRoles = - InjectivePermissionsV1Beta1Permissions.AddressRoles -export type GrpcPermissionsRole = InjectivePermissionsV1Beta1Permissions.Role -export type GrpcPermissionsRoleIDs = - InjectivePermissionsV1Beta1Permissions.RoleIDs -export type GrpcPermissionsAddressVoucher = - InjectivePermissionsV1Beta1Permissions.AddressVoucher -export type GrpcPermissionVoucher = - InjectivePermissionsV1Beta1Permissions.Voucher -export type GrpcPermissionsParams = InjectivePermissionsV1Beta1Params.Params + InjectivePermissionsV1Beta1Permissions, + InjectivePermissionsV1Beta1Params + } from '@injectivelabs/core-proto-ts' + +import { Coin } from '@injectivelabs/ts-types + + export interface Namespace { + denom: string + wasmHook: string + mintsPaused: boolean + sendsPaused: boolean + burnsPaused: boolean + rolePermissions: Role[] + addressRoles: AddressRoles[] + + } + + export interface PermissionsModuleParams { + wasmHookQueryMaxGas: string + } + + + export interface AddressRoles { + address: string + roles: string[] + } + + + export interface Role { + role: string + permissions: number + } + + + export interface RoleIDs { + roleIds: number[] + } + + export interface Voucher { + coins: Coin[] + } + + export interface AddressVoucher { + address: string + voucher?: Voucher + } + + export type GrpcPermissionsNamespace = InjectivePermissionsV1Beta1Permissions.Namespace + export type GrpcPermissionsAddressRoles = InjectivePermissionsV1Beta1Permissions.AddressRoles + export type GrpcPermissionsRole = InjectivePermissionsV1Beta1Permissions.Role + export type GrpcPermissionsRoleIDs = InjectivePermissionsV1Beta1Permissions.RoleIDs + export type GrpcPermissionsAddressVoucher = InjectivePermissionsV1Beta1Permissions.AddressVoucher + export type GrpcPermissionVoucher = InjectivePermissionsV1Beta1Permissions.Voucher + export type GrpcPermissionsParams = InjectivePermissionsV1Beta1Params.Params