@arcblock/did-util 1.30.26 → 1.31.0

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/esm/cbor.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { toDelegateAddress, toStakeAddress } from "./shared.mjs";
1
+ import { toDelegateAddress, toStakeAddress, toTokenCharterAssetAddress } from "./shared.mjs";
2
2
  import { TCreateAssetTx, TCreateFactoryTx, TCreateRollupTx, TCreateTokenFactoryTx, TCreateTokenTx } from "@ocap/types";
3
3
 
4
4
  //#region src/cbor.d.ts
@@ -9,4 +9,4 @@ declare const toTokenAddress: (itx: Partial<TCreateTokenTx>) => string;
9
9
  declare const toTokenFactoryAddress: (itx: Partial<TCreateTokenFactoryTx>) => string;
10
10
  declare const toRollupAddress: (itx: Partial<TCreateRollupTx>) => string;
11
11
  //#endregion
12
- export { toAssetAddress, toDelegateAddress, toFactoryAddress, toItxAddress, toRollupAddress, toStakeAddress, toTokenAddress, toTokenFactoryAddress };
12
+ export { toAssetAddress, toDelegateAddress, toFactoryAddress, toItxAddress, toRollupAddress, toStakeAddress, toTokenAddress, toTokenCharterAssetAddress, toTokenFactoryAddress };
package/esm/cbor.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { makeCurriedAddress, toDelegateAddress, toStakeAddress } from "./shared.mjs";
1
+ import { makeCurriedAddress, toDelegateAddress, toStakeAddress, toTokenCharterAssetAddress } from "./shared.mjs";
2
2
  import { fromHash } from "@arcblock/did";
3
3
  import { Hasher, types } from "@ocap/mcrypto";
4
4
  import { canonicalBytes } from "@ocap/message/cbor";
@@ -33,4 +33,4 @@ const toTokenFactoryAddress = curriedAddress("CreateTokenFactoryTx", types.RoleT
33
33
  const toRollupAddress = curriedAddress("CreateRollupTx", types.RoleType.ROLE_ROLLUP);
34
34
 
35
35
  //#endregion
36
- export { toAssetAddress, toDelegateAddress, toFactoryAddress, toItxAddress, toRollupAddress, toStakeAddress, toTokenAddress, toTokenFactoryAddress };
36
+ export { toAssetAddress, toDelegateAddress, toFactoryAddress, toItxAddress, toRollupAddress, toStakeAddress, toTokenAddress, toTokenCharterAssetAddress, toTokenFactoryAddress };
package/esm/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { toDelegateAddress, toStakeAddress } from "./shared.mjs";
1
+ import { toDelegateAddress, toStakeAddress, toTokenCharterAssetAddress } from "./shared.mjs";
2
2
  import { TCreateAssetTx, TCreateFactoryTx, TCreateRollupTx, TCreateTokenFactoryTx, TCreateTokenTx } from "@ocap/types";
3
3
 
4
4
  //#region src/index.d.ts
@@ -20,4 +20,4 @@ declare const toTokenAddress: (itx: Partial<TCreateTokenTx>, encoding: ItxEncodi
20
20
  declare const toTokenFactoryAddress: (itx: Partial<TCreateTokenFactoryTx>, encoding: ItxEncoding) => string;
21
21
  declare const toRollupAddress: (itx: Partial<TCreateRollupTx>, encoding: ItxEncoding) => string;
22
22
  //#endregion
23
- export { ItxEncoding, toAssetAddress, toDelegateAddress, toFactoryAddress, toItxAddress, toRollupAddress, toStakeAddress, toTokenAddress, toTokenFactoryAddress };
23
+ export { ItxEncoding, toAssetAddress, toDelegateAddress, toFactoryAddress, toItxAddress, toRollupAddress, toStakeAddress, toTokenAddress, toTokenCharterAssetAddress, toTokenFactoryAddress };
package/esm/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { toDelegateAddress, toStakeAddress } from "./shared.mjs";
1
+ import { toDelegateAddress, toStakeAddress, toTokenCharterAssetAddress } from "./shared.mjs";
2
2
  import { toItxAddress as toItxAddress$1 } from "./cbor.mjs";
3
3
  import { toItxAddress as toItxAddress$2 } from "./protobuf.mjs";
4
4
  import { types } from "@ocap/mcrypto";
@@ -37,4 +37,4 @@ const toTokenFactoryAddress = curriedAddress("CreateTokenFactoryTx", types.RoleT
37
37
  const toRollupAddress = curriedAddress("CreateRollupTx", types.RoleType.ROLE_ROLLUP);
38
38
 
39
39
  //#endregion
40
- export { toAssetAddress, toDelegateAddress, toFactoryAddress, toItxAddress, toRollupAddress, toStakeAddress, toTokenAddress, toTokenFactoryAddress };
40
+ export { toAssetAddress, toDelegateAddress, toFactoryAddress, toItxAddress, toRollupAddress, toStakeAddress, toTokenAddress, toTokenCharterAssetAddress, toTokenFactoryAddress };
@@ -1,4 +1,4 @@
1
- import { toDelegateAddress, toStakeAddress } from "./shared.mjs";
1
+ import { toDelegateAddress, toStakeAddress, toTokenCharterAssetAddress } from "./shared.mjs";
2
2
  import { TCreateAssetTx, TCreateFactoryTx, TCreateRollupTx, TCreateTokenFactoryTx, TCreateTokenTx } from "@ocap/types";
3
3
 
4
4
  //#region src/protobuf.d.ts
@@ -9,4 +9,4 @@ declare const toTokenAddress: (itx: Partial<TCreateTokenTx>) => string;
9
9
  declare const toTokenFactoryAddress: (itx: Partial<TCreateTokenFactoryTx>) => string;
10
10
  declare const toRollupAddress: (itx: Partial<TCreateRollupTx>) => string;
11
11
  //#endregion
12
- export { toAssetAddress, toDelegateAddress, toFactoryAddress, toItxAddress, toRollupAddress, toStakeAddress, toTokenAddress, toTokenFactoryAddress };
12
+ export { toAssetAddress, toDelegateAddress, toFactoryAddress, toItxAddress, toRollupAddress, toStakeAddress, toTokenAddress, toTokenCharterAssetAddress, toTokenFactoryAddress };
package/esm/protobuf.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { makeCurriedAddress, toDelegateAddress, toStakeAddress } from "./shared.mjs";
1
+ import { makeCurriedAddress, toDelegateAddress, toStakeAddress, toTokenCharterAssetAddress } from "./shared.mjs";
2
2
  import { fromHash } from "@arcblock/did";
3
3
  import { Hasher, types } from "@ocap/mcrypto";
4
4
  import { createMessage } from "@ocap/message";
@@ -25,4 +25,4 @@ const toTokenFactoryAddress = curriedAddress("CreateTokenFactoryTx", types.RoleT
25
25
  const toRollupAddress = curriedAddress("CreateRollupTx", types.RoleType.ROLE_ROLLUP);
26
26
 
27
27
  //#endregion
28
- export { toAssetAddress, toDelegateAddress, toFactoryAddress, toItxAddress, toRollupAddress, toStakeAddress, toTokenAddress, toTokenFactoryAddress };
28
+ export { toAssetAddress, toDelegateAddress, toFactoryAddress, toItxAddress, toRollupAddress, toStakeAddress, toTokenAddress, toTokenCharterAssetAddress, toTokenFactoryAddress };
package/esm/shared.d.mts CHANGED
@@ -3,5 +3,10 @@ type ToItxAddressFn = (itx: Record<string, unknown>, type: string, role: number)
3
3
  declare function makeCurriedAddress(toItxAddress: ToItxAddressFn): (type: string, role: number) => (itx: Record<string, unknown>) => string;
4
4
  declare function toStakeAddress(sender: string, receiver: string, nonce?: string): string;
5
5
  declare function toDelegateAddress(delegator: string, delegatee: string): string;
6
+ /**
7
+ * Deterministically derive the companion Master Charter NFT address (`ROLE_ASSET`)
8
+ * for a given Fungible Token address (`ROLE_TOKEN`).
9
+ */
10
+ declare function toTokenCharterAssetAddress(tokenAddress: string): string;
6
11
  //#endregion
7
- export { ToItxAddressFn, makeCurriedAddress, toDelegateAddress, toStakeAddress };
12
+ export { ToItxAddressFn, makeCurriedAddress, toDelegateAddress, toStakeAddress, toTokenCharterAssetAddress };
package/esm/shared.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { fromHash } from "@arcblock/did";
2
2
  import { Hasher, types } from "@ocap/mcrypto";
3
+ import { toAddress } from "@ocap/util";
3
4
 
4
5
  //#region src/shared.ts
5
6
  /**
@@ -30,6 +31,16 @@ function toDelegateAddress(delegator, delegatee) {
30
31
  const buffer = Buffer.concat([Uint8Array.from(Buffer.from(delegator)), Uint8Array.from(Buffer.from(delegatee))]);
31
32
  return fromHash(Hasher.SHA3.hash256(buffer), types.RoleType.ROLE_DELEGATION);
32
33
  }
34
+ /**
35
+ * Deterministically derive the companion Master Charter NFT address (`ROLE_ASSET`)
36
+ * for a given Fungible Token address (`ROLE_TOKEN`).
37
+ */
38
+ function toTokenCharterAssetAddress(tokenAddress) {
39
+ if (typeof tokenAddress !== "string" || !tokenAddress.trim()) throw new Error("tokenAddress must be a non-empty string");
40
+ const normalized = toAddress(tokenAddress.trim());
41
+ const buffer = Uint8Array.from(Buffer.from(`token-charter:${normalized}`));
42
+ return fromHash(Hasher.SHA3.hash256(buffer), types.RoleType.ROLE_ASSET);
43
+ }
33
44
 
34
45
  //#endregion
35
- export { makeCurriedAddress, toDelegateAddress, toStakeAddress };
46
+ export { makeCurriedAddress, toDelegateAddress, toStakeAddress, toTokenCharterAssetAddress };
package/lib/cbor.cjs CHANGED
@@ -40,4 +40,5 @@ exports.toItxAddress = toItxAddress;
40
40
  exports.toRollupAddress = toRollupAddress;
41
41
  exports.toStakeAddress = require_shared.toStakeAddress;
42
42
  exports.toTokenAddress = toTokenAddress;
43
+ exports.toTokenCharterAssetAddress = require_shared.toTokenCharterAssetAddress;
43
44
  exports.toTokenFactoryAddress = toTokenFactoryAddress;
package/lib/cbor.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { toDelegateAddress, toStakeAddress } from "./shared.cjs";
1
+ import { toDelegateAddress, toStakeAddress, toTokenCharterAssetAddress } from "./shared.cjs";
2
2
  import { TCreateAssetTx, TCreateFactoryTx, TCreateRollupTx, TCreateTokenFactoryTx, TCreateTokenTx } from "@ocap/types";
3
3
 
4
4
  //#region src/cbor.d.ts
@@ -9,4 +9,4 @@ declare const toTokenAddress: (itx: Partial<TCreateTokenTx>) => string;
9
9
  declare const toTokenFactoryAddress: (itx: Partial<TCreateTokenFactoryTx>) => string;
10
10
  declare const toRollupAddress: (itx: Partial<TCreateRollupTx>) => string;
11
11
  //#endregion
12
- export { toAssetAddress, toDelegateAddress, toFactoryAddress, toItxAddress, toRollupAddress, toStakeAddress, toTokenAddress, toTokenFactoryAddress };
12
+ export { toAssetAddress, toDelegateAddress, toFactoryAddress, toItxAddress, toRollupAddress, toStakeAddress, toTokenAddress, toTokenCharterAssetAddress, toTokenFactoryAddress };
package/lib/index.cjs CHANGED
@@ -44,4 +44,5 @@ exports.toItxAddress = toItxAddress;
44
44
  exports.toRollupAddress = toRollupAddress;
45
45
  exports.toStakeAddress = require_shared.toStakeAddress;
46
46
  exports.toTokenAddress = toTokenAddress;
47
+ exports.toTokenCharterAssetAddress = require_shared.toTokenCharterAssetAddress;
47
48
  exports.toTokenFactoryAddress = toTokenFactoryAddress;
package/lib/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { toDelegateAddress, toStakeAddress } from "./shared.cjs";
1
+ import { toDelegateAddress, toStakeAddress, toTokenCharterAssetAddress } from "./shared.cjs";
2
2
  import { TCreateAssetTx, TCreateFactoryTx, TCreateRollupTx, TCreateTokenFactoryTx, TCreateTokenTx } from "@ocap/types";
3
3
 
4
4
  //#region src/index.d.ts
@@ -20,4 +20,4 @@ declare const toTokenAddress: (itx: Partial<TCreateTokenTx>, encoding: ItxEncodi
20
20
  declare const toTokenFactoryAddress: (itx: Partial<TCreateTokenFactoryTx>, encoding: ItxEncoding) => string;
21
21
  declare const toRollupAddress: (itx: Partial<TCreateRollupTx>, encoding: ItxEncoding) => string;
22
22
  //#endregion
23
- export { ItxEncoding, toAssetAddress, toDelegateAddress, toFactoryAddress, toItxAddress, toRollupAddress, toStakeAddress, toTokenAddress, toTokenFactoryAddress };
23
+ export { ItxEncoding, toAssetAddress, toDelegateAddress, toFactoryAddress, toItxAddress, toRollupAddress, toStakeAddress, toTokenAddress, toTokenCharterAssetAddress, toTokenFactoryAddress };
package/lib/protobuf.cjs CHANGED
@@ -32,4 +32,5 @@ exports.toItxAddress = toItxAddress;
32
32
  exports.toRollupAddress = toRollupAddress;
33
33
  exports.toStakeAddress = require_shared.toStakeAddress;
34
34
  exports.toTokenAddress = toTokenAddress;
35
+ exports.toTokenCharterAssetAddress = require_shared.toTokenCharterAssetAddress;
35
36
  exports.toTokenFactoryAddress = toTokenFactoryAddress;
@@ -1,4 +1,4 @@
1
- import { toDelegateAddress, toStakeAddress } from "./shared.cjs";
1
+ import { toDelegateAddress, toStakeAddress, toTokenCharterAssetAddress } from "./shared.cjs";
2
2
  import { TCreateAssetTx, TCreateFactoryTx, TCreateRollupTx, TCreateTokenFactoryTx, TCreateTokenTx } from "@ocap/types";
3
3
 
4
4
  //#region src/protobuf.d.ts
@@ -9,4 +9,4 @@ declare const toTokenAddress: (itx: Partial<TCreateTokenTx>) => string;
9
9
  declare const toTokenFactoryAddress: (itx: Partial<TCreateTokenFactoryTx>) => string;
10
10
  declare const toRollupAddress: (itx: Partial<TCreateRollupTx>) => string;
11
11
  //#endregion
12
- export { toAssetAddress, toDelegateAddress, toFactoryAddress, toItxAddress, toRollupAddress, toStakeAddress, toTokenAddress, toTokenFactoryAddress };
12
+ export { toAssetAddress, toDelegateAddress, toFactoryAddress, toItxAddress, toRollupAddress, toStakeAddress, toTokenAddress, toTokenCharterAssetAddress, toTokenFactoryAddress };
package/lib/shared.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  let _arcblock_did = require("@arcblock/did");
2
2
  let _ocap_mcrypto = require("@ocap/mcrypto");
3
+ let _ocap_util = require("@ocap/util");
3
4
 
4
5
  //#region src/shared.ts
5
6
  /**
@@ -30,8 +31,19 @@ function toDelegateAddress(delegator, delegatee) {
30
31
  const buffer = Buffer.concat([Uint8Array.from(Buffer.from(delegator)), Uint8Array.from(Buffer.from(delegatee))]);
31
32
  return (0, _arcblock_did.fromHash)(_ocap_mcrypto.Hasher.SHA3.hash256(buffer), _ocap_mcrypto.types.RoleType.ROLE_DELEGATION);
32
33
  }
34
+ /**
35
+ * Deterministically derive the companion Master Charter NFT address (`ROLE_ASSET`)
36
+ * for a given Fungible Token address (`ROLE_TOKEN`).
37
+ */
38
+ function toTokenCharterAssetAddress(tokenAddress) {
39
+ if (typeof tokenAddress !== "string" || !tokenAddress.trim()) throw new Error("tokenAddress must be a non-empty string");
40
+ const normalized = (0, _ocap_util.toAddress)(tokenAddress.trim());
41
+ const buffer = Uint8Array.from(Buffer.from(`token-charter:${normalized}`));
42
+ return (0, _arcblock_did.fromHash)(_ocap_mcrypto.Hasher.SHA3.hash256(buffer), _ocap_mcrypto.types.RoleType.ROLE_ASSET);
43
+ }
33
44
 
34
45
  //#endregion
35
46
  exports.makeCurriedAddress = makeCurriedAddress;
36
47
  exports.toDelegateAddress = toDelegateAddress;
37
- exports.toStakeAddress = toStakeAddress;
48
+ exports.toStakeAddress = toStakeAddress;
49
+ exports.toTokenCharterAssetAddress = toTokenCharterAssetAddress;
package/lib/shared.d.cts CHANGED
@@ -3,5 +3,10 @@ type ToItxAddressFn = (itx: Record<string, unknown>, type: string, role: number)
3
3
  declare function makeCurriedAddress(toItxAddress: ToItxAddressFn): (type: string, role: number) => (itx: Record<string, unknown>) => string;
4
4
  declare function toStakeAddress(sender: string, receiver: string, nonce?: string): string;
5
5
  declare function toDelegateAddress(delegator: string, delegatee: string): string;
6
+ /**
7
+ * Deterministically derive the companion Master Charter NFT address (`ROLE_ASSET`)
8
+ * for a given Fungible Token address (`ROLE_TOKEN`).
9
+ */
10
+ declare function toTokenCharterAssetAddress(tokenAddress: string): string;
6
11
  //#endregion
7
- export { ToItxAddressFn, makeCurriedAddress, toDelegateAddress, toStakeAddress };
12
+ export { ToItxAddressFn, makeCurriedAddress, toDelegateAddress, toStakeAddress, toTokenCharterAssetAddress };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arcblock/did-util",
3
3
  "description": "Helper function to calculate did",
4
- "version": "1.30.26",
4
+ "version": "1.31.0",
5
5
  "type": "module",
6
6
  "author": {
7
7
  "name": "wangshijun",
@@ -19,13 +19,13 @@
19
19
  "wangshijun <shijun@arcblock.io> (https://github.com/wangshijun)"
20
20
  ],
21
21
  "dependencies": {
22
- "@arcblock/did": "1.30.26",
23
- "@ocap/mcrypto": "1.30.26",
24
- "@ocap/message": "1.30.26",
25
- "@ocap/proto": "1.30.26",
26
- "@ocap/types": "1.30.26",
27
- "@ocap/util": "1.30.26",
28
- "@ocap/wallet": "1.30.26"
22
+ "@arcblock/did": "1.31.0",
23
+ "@ocap/mcrypto": "1.31.0",
24
+ "@ocap/message": "1.31.0",
25
+ "@ocap/proto": "1.31.0",
26
+ "@ocap/types": "1.31.0",
27
+ "@ocap/util": "1.31.0",
28
+ "@ocap/wallet": "1.31.0"
29
29
  },
30
30
  "sideEffects": false,
31
31
  "main": "./lib/index.cjs",