@blocklet/meta 1.16.0-beta-1d6c582e → 1.16.0-beta-62b42401

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.
@@ -0,0 +1,15 @@
1
+ export declare function createImageData(size: number): number[];
2
+ export declare function buildOpts(opts: {
3
+ seed: string;
4
+ size?: number;
5
+ scale?: number;
6
+ }): BlockiesOptions;
7
+ export interface BlockiesOptions {
8
+ seed: string;
9
+ size: number;
10
+ scale: number;
11
+ color: string;
12
+ bgcolor: string;
13
+ spotcolor: string;
14
+ }
15
+ export declare function createBlockiesSvg(address: string, size?: number, caseSensitive?: boolean, scale?: number): string;
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ /* eslint-disable no-bitwise */
3
+ /* eslint-disable prefer-destructuring */
4
+ // Forked from https://github.com/download13/blockies
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createBlockiesSvg = exports.buildOpts = exports.createImageData = void 0;
7
+ // The random number is a js implementation of the Xorshift PRNG
8
+ const randseed = new Array(4); // Xorshift: [x, y, z, w] 32 bit values
9
+ function seedrand(seed) {
10
+ randseed.fill(0);
11
+ for (let i = 0; i < seed.length; i++) {
12
+ randseed[i % 4] = (randseed[i % 4] << 5) - randseed[i % 4] + seed.charCodeAt(i);
13
+ }
14
+ }
15
+ function rand() {
16
+ // based on Java's String.hashCode(), expanded to 4 32bit values
17
+ const t = randseed[0] ^ (randseed[0] << 11);
18
+ randseed[0] = randseed[1];
19
+ randseed[1] = randseed[2];
20
+ randseed[2] = randseed[3];
21
+ randseed[3] = randseed[3] ^ (randseed[3] >> 19) ^ t ^ (t >> 8);
22
+ return (randseed[3] >>> 0) / ((1 << 31) >>> 0);
23
+ }
24
+ function createColor() {
25
+ // saturation is the whole color spectrum
26
+ const h = Math.floor(rand() * 360);
27
+ // saturation goes from 40 to 100, it avoids greyish colors
28
+ const s = `${(rand() * 60 + 40).toFixed(1)}%`;
29
+ // lightness can be anything from 0 to 100, but probabilities are a bell curve around 50%
30
+ const l = `${((rand() + rand() + rand() + rand()) * 25).toFixed(1)}%`;
31
+ return `hsl(${h},${s},${l})`;
32
+ }
33
+ function createImageData(size) {
34
+ const width = size; // Only support square icons for now
35
+ const height = size;
36
+ const dataWidth = Math.ceil(width / 2);
37
+ const mirrorWidth = width - dataWidth;
38
+ const data = [];
39
+ for (let y = 0; y < height; y++) {
40
+ let row = [];
41
+ for (let x = 0; x < dataWidth; x++) {
42
+ // this makes foreground and background color to have a 43% (1/2.3) probability
43
+ // spot color has 13% chance
44
+ row[x] = Math.floor(rand() * 2.3);
45
+ }
46
+ const r = row.slice(0, mirrorWidth);
47
+ r.reverse();
48
+ row = row.concat(r);
49
+ for (let i = 0; i < row.length; i++) {
50
+ data.push(row[i]);
51
+ }
52
+ }
53
+ return data;
54
+ }
55
+ exports.createImageData = createImageData;
56
+ function buildOpts(opts) {
57
+ seedrand(opts.seed);
58
+ const newOpts = {
59
+ seed: opts.seed,
60
+ size: opts.size || 8,
61
+ scale: opts.scale || 10,
62
+ color: createColor(),
63
+ bgcolor: createColor(),
64
+ spotcolor: createColor(),
65
+ };
66
+ return newOpts;
67
+ }
68
+ exports.buildOpts = buildOpts;
69
+ function createBlockiesSvg(address, size = 8, caseSensitive = false, scale = 10) {
70
+ if (!address)
71
+ throw new Error('Address is required');
72
+ const opts = buildOpts({ seed: caseSensitive ? address : address.toLowerCase(), size, scale });
73
+ const imageData = createImageData(opts.size);
74
+ const width = size * scale;
75
+ const shapes = imageData
76
+ ?.map((value, i) => {
77
+ if (value === 1) {
78
+ const row = (i % size) * scale;
79
+ const col = Math.floor(i / size) * scale;
80
+ return `<rect width="${scale}" height="${scale}" x="${row}" y="${col}" />`;
81
+ }
82
+ return null;
83
+ })
84
+ .filter(Boolean)
85
+ .join('');
86
+ const spots = imageData
87
+ ?.map((value, i) => {
88
+ if (value === 2) {
89
+ const row = (i % size) * scale;
90
+ const col = Math.floor(i / size) * scale;
91
+ return `<rect width="${scale}" height="${scale}" x="${row}" y="${col}" />`;
92
+ }
93
+ return null;
94
+ })
95
+ .filter(Boolean)
96
+ .join('');
97
+ return `
98
+ <svg width="${width}" height="${width}" viewBox="0 0 ${width} ${width}" xmlns="http://www.w3.org/2000/svg">
99
+ <rect width="${width}" height="${width}" fill="${opts.bgcolor}" />
100
+ <g fill="${opts.color}">
101
+ ${shapes}
102
+ </g>
103
+ <g fill="${opts.spotcolor}">
104
+ ${spots}
105
+ </g>
106
+ </svg>`;
107
+ }
108
+ exports.createBlockiesSvg = createBlockiesSvg;
package/lib/index.d.ts CHANGED
@@ -67,7 +67,7 @@ declare const _default: {
67
67
  fixName: (meta: any) => any;
68
68
  fixService: (meta: import("./types").TBlockletMeta) => import("./types").TBlockletMeta;
69
69
  toBlockletDid: (name: string | Buffer) => string;
70
- getBlockletWallet: (blockletDid: string, nodeSk?: string, type?: string | import("@arcblock/did").DIDType, index?: number) => import("@ocap/wallet").WalletObject<string>;
70
+ getBlockletWallet: (didOrSk: string, nodeSk?: string, type?: "default" | "eth" | import("@arcblock/did").DIDType, index?: number) => import("@ocap/wallet").WalletObject<string>;
71
71
  getBlockletInfo: (state: import("@abtnode/client").BlockletState, nodeSk?: string, { returnWallet }?: {
72
72
  returnWallet?: boolean;
73
73
  }) => {
@@ -507,7 +507,15 @@ function parseNavigation(blocklet = {}, options = {}) {
507
507
  const splitNavigation = splitNavigationBySection(patchedNavigation);
508
508
  // 将 footer-social, footer-bottom, sessionManager 的二级菜单提升为一级菜单
509
509
  const levelUpNavigation = splitNavigation.reduce((all, cur) => {
510
- if (['bottom', 'social', 'sessionManager'].includes(cur.section)) {
510
+ const shouldLevelUp = ['bottom', 'social', 'sessionManager'].includes(cur.section);
511
+ let isRoot = false;
512
+ // 在更新为容器模式后,最终生成的 navigation 会将 '/' 的子菜单提升为一级菜单
513
+ // 同时兼容非容器模式(root-blocklet 不会出现在 components 中)
514
+ const rootBlocklet = components.find((item) => item.link === '/');
515
+ if (rootBlocklet && cur.id === rootBlocklet.did) {
516
+ isRoot = true;
517
+ }
518
+ if (shouldLevelUp || isRoot) {
511
519
  if (cur.items && cur.items.length > 0) {
512
520
  all.push(...cur.items.map((x) => {
513
521
  const { section } = cur;
@@ -517,6 +525,10 @@ function parseNavigation(blocklet = {}, options = {}) {
517
525
  }));
518
526
  return all;
519
527
  }
528
+ // root blocklet 不应该出现在菜单中
529
+ if (isRoot) {
530
+ return all;
531
+ }
520
532
  }
521
533
  all.push(cur);
522
534
  return all;
package/lib/wallet.d.ts CHANGED
@@ -5,5 +5,5 @@ import { DIDType } from '@arcblock/did';
5
5
  *
6
6
  * Spec: https://github.com/ArcBlock/ABT-DID-Protocol#request-did-authentication
7
7
  */
8
- declare const getApplicationWallet: (blockletDid: string, nodeSk?: string, type?: DIDType | string, index?: number) => WalletObject;
8
+ declare const getApplicationWallet: (didOrSk: string, nodeSk?: string, type?: DIDType | 'default' | 'eth', index?: number) => WalletObject;
9
9
  export = getApplicationWallet;
package/lib/wallet.js CHANGED
@@ -3,16 +3,31 @@ const mcrypto_1 = require("@ocap/mcrypto");
3
3
  const wallet_1 = require("@ocap/wallet");
4
4
  const did_1 = require("@arcblock/did");
5
5
  const did_ext_1 = require("@arcblock/did-ext");
6
+ const defaults = { role: mcrypto_1.types.RoleType.ROLE_APPLICATION };
6
7
  /**
7
8
  * Gen DID from blocklet did and nodeSk
8
9
  *
9
10
  * Spec: https://github.com/ArcBlock/ABT-DID-Protocol#request-did-authentication
10
11
  */
11
- const getApplicationWallet = (blockletDid, nodeSk, type, index) => {
12
- const t = type || { role: mcrypto_1.types.RoleType.ROLE_APPLICATION };
13
- if (!(0, did_1.isValid)(blockletDid)) {
12
+ const getApplicationWallet = (didOrSk, nodeSk, type, index) => {
13
+ let t = type || defaults;
14
+ const isEthereum = (0, did_1.isEthereumType)((0, did_1.DidType)(type));
15
+ if (isEthereum) {
16
+ t = (0, wallet_1.WalletType)(type);
17
+ }
18
+ else {
19
+ t = (0, wallet_1.WalletType)(defaults);
20
+ }
21
+ if (!(0, did_1.isValid)(didOrSk)) {
22
+ let sk = '';
14
23
  try {
15
- return (0, wallet_1.fromSecretKey)(blockletDid, t);
24
+ if (isEthereum) {
25
+ sk = didOrSk.slice(0, 66);
26
+ }
27
+ else {
28
+ sk = didOrSk;
29
+ }
30
+ return (0, wallet_1.fromSecretKey)(sk, t);
16
31
  }
17
32
  catch (err) {
18
33
  throw new Error(`Cannot get blocklet wallet with invalid blocklet did or custom sk: ${err.message}`);
@@ -21,6 +36,6 @@ const getApplicationWallet = (blockletDid, nodeSk, type, index) => {
21
36
  if (!nodeSk) {
22
37
  throw new Error('Cannot get blocklet wallet with empty node sk');
23
38
  }
24
- return (0, did_ext_1.fromAppDid)(blockletDid, nodeSk, t, index || 0);
39
+ return (0, did_ext_1.fromAppDid)(didOrSk, nodeSk, t, index || 0);
25
40
  };
26
41
  module.exports = getApplicationWallet;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.0-beta-1d6c582e",
6
+ "version": "1.16.0-beta-62b42401",
7
7
  "description": "Library to parse/validate/fix blocklet meta",
8
8
  "main": "./lib/index.js",
9
9
  "typings": "./lib/index.d.ts",
@@ -24,19 +24,19 @@
24
24
  "author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
- "@abtnode/client": "1.16.0-beta-1d6c582e",
28
- "@abtnode/constant": "1.16.0-beta-1d6c582e",
29
- "@abtnode/util": "1.16.0-beta-1d6c582e",
30
- "@arcblock/did": "1.18.62",
31
- "@arcblock/did-ext": "1.18.62",
32
- "@arcblock/did-util": "1.18.62",
33
- "@arcblock/jwt": "1.18.62",
34
- "@blocklet/constant": "1.16.0-beta-1d6c582e",
35
- "@ocap/asset": "1.18.62",
36
- "@ocap/mcrypto": "1.18.62",
37
- "@ocap/types": "1.18.62",
38
- "@ocap/util": "1.18.62",
39
- "@ocap/wallet": "1.18.62",
27
+ "@abtnode/client": "1.16.0-beta-62b42401",
28
+ "@abtnode/constant": "1.16.0-beta-62b42401",
29
+ "@abtnode/util": "1.16.0-beta-62b42401",
30
+ "@arcblock/did": "1.18.63",
31
+ "@arcblock/did-ext": "1.18.63",
32
+ "@arcblock/did-util": "1.18.63",
33
+ "@arcblock/jwt": "1.18.63",
34
+ "@blocklet/constant": "1.16.0-beta-62b42401",
35
+ "@ocap/asset": "1.18.63",
36
+ "@ocap/mcrypto": "1.18.63",
37
+ "@ocap/types": "1.18.63",
38
+ "@ocap/util": "1.18.63",
39
+ "@ocap/wallet": "1.18.63",
40
40
  "ajv": "^8.11.0",
41
41
  "axios": "^0.27.2",
42
42
  "cjk-length": "^1.0.0",
@@ -59,7 +59,7 @@
59
59
  "validate-npm-package-name": "^3.0.0"
60
60
  },
61
61
  "devDependencies": {
62
- "@abtnode/client": "^1.8.68",
62
+ "@abtnode/client": "1.8.68",
63
63
  "@arcblock/eslint-config-ts": "^0.2.3",
64
64
  "@types/express": "^4.17.14",
65
65
  "@types/jest": "^29.2.2",
@@ -81,5 +81,5 @@
81
81
  "ts-node": "^10.9.1",
82
82
  "typescript": "^4.8.4"
83
83
  },
84
- "gitHead": "209fa1413ae05d8961942b2c21f2d83df66f4b68"
84
+ "gitHead": "6ef1c3601d0cfdcf5da0b55b4c54ef1fa9fce7d2"
85
85
  }