@metamask-previews/design-system-shared 0.0.0-preview.374d60e
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/CHANGELOG.md +10 -0
- package/LICENSE +20 -0
- package/README.md +15 -0
- package/dist/index.cjs +20 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +11 -0
- package/dist/index.mjs.map +1 -0
- package/dist/utils/caip-address.cjs +89 -0
- package/dist/utils/caip-address.cjs.map +1 -0
- package/dist/utils/caip-address.d.cts +55 -0
- package/dist/utils/caip-address.d.cts.map +1 -0
- package/dist/utils/caip-address.d.mts +55 -0
- package/dist/utils/caip-address.d.mts.map +1 -0
- package/dist/utils/caip-address.mjs +81 -0
- package/dist/utils/caip-address.mjs.map +1 -0
- package/package.json +67 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
[Unreleased]: https://github.com/MetaMask/metamask-design-system/
|
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 MetaMask
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# `@metamask/design-system-shared`
|
|
2
|
+
|
|
3
|
+
Shared types for design system libraries
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
`yarn add @metamask/design-system-shared`
|
|
8
|
+
|
|
9
|
+
or
|
|
10
|
+
|
|
11
|
+
`npm install @metamask/design-system-shared`
|
|
12
|
+
|
|
13
|
+
## Contributing
|
|
14
|
+
|
|
15
|
+
This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/metamask-design-system#readme).
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateIconSeed = exports.isEthereumAddress = exports.generateSeedNonEthereum = exports.generateSeedEthereum = exports.extractAccountAddress = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Example function that returns a greeting for the given name.
|
|
6
|
+
*
|
|
7
|
+
* @param name - The name to greet.
|
|
8
|
+
* @returns The greeting.
|
|
9
|
+
*/
|
|
10
|
+
function greeter(name) {
|
|
11
|
+
return `Hello, ${name}!`;
|
|
12
|
+
}
|
|
13
|
+
exports.default = greeter;
|
|
14
|
+
var caip_address_1 = require("./utils/caip-address.cjs");
|
|
15
|
+
Object.defineProperty(exports, "extractAccountAddress", { enumerable: true, get: function () { return caip_address_1.extractAccountAddress; } });
|
|
16
|
+
Object.defineProperty(exports, "generateSeedEthereum", { enumerable: true, get: function () { return caip_address_1.generateSeedEthereum; } });
|
|
17
|
+
Object.defineProperty(exports, "generateSeedNonEthereum", { enumerable: true, get: function () { return caip_address_1.generateSeedNonEthereum; } });
|
|
18
|
+
Object.defineProperty(exports, "isEthereumAddress", { enumerable: true, get: function () { return caip_address_1.isEthereumAddress; } });
|
|
19
|
+
Object.defineProperty(exports, "generateIconSeed", { enumerable: true, get: function () { return caip_address_1.generateIconSeed; } });
|
|
20
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,SAAwB,OAAO,CAAC,IAAY;IAC1C,OAAO,UAAU,IAAI,GAAG,CAAC;AAC3B,CAAC;AAFD,0BAEC;AAED,yDAM8B;AAL5B,qHAAA,qBAAqB,OAAA;AACrB,oHAAA,oBAAoB,OAAA;AACpB,uHAAA,uBAAuB,OAAA;AACvB,iHAAA,iBAAiB,OAAA;AACjB,gHAAA,gBAAgB,OAAA","sourcesContent":["/**\n * Example function that returns a greeting for the given name.\n *\n * @param name - The name to greet.\n * @returns The greeting.\n */\nexport default function greeter(name: string): string {\n return `Hello, ${name}!`;\n}\n\nexport {\n extractAccountAddress,\n generateSeedEthereum,\n generateSeedNonEthereum,\n isEthereumAddress,\n generateIconSeed,\n} from './utils/caip-address';\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example function that returns a greeting for the given name.
|
|
3
|
+
*
|
|
4
|
+
* @param name - The name to greet.
|
|
5
|
+
* @returns The greeting.
|
|
6
|
+
*/
|
|
7
|
+
export default function greeter(name: string): string;
|
|
8
|
+
export { extractAccountAddress, generateSeedEthereum, generateSeedNonEthereum, isEthereumAddress, generateIconSeed, } from "./utils/caip-address.cjs";
|
|
9
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,iBAAiB,EACjB,gBAAgB,GACjB,iCAA6B"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example function that returns a greeting for the given name.
|
|
3
|
+
*
|
|
4
|
+
* @param name - The name to greet.
|
|
5
|
+
* @returns The greeting.
|
|
6
|
+
*/
|
|
7
|
+
export default function greeter(name: string): string;
|
|
8
|
+
export { extractAccountAddress, generateSeedEthereum, generateSeedNonEthereum, isEthereumAddress, generateIconSeed, } from "./utils/caip-address.mjs";
|
|
9
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,iBAAiB,EACjB,gBAAgB,GACjB,iCAA6B"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example function that returns a greeting for the given name.
|
|
3
|
+
*
|
|
4
|
+
* @param name - The name to greet.
|
|
5
|
+
* @returns The greeting.
|
|
6
|
+
*/
|
|
7
|
+
export default function greeter(name) {
|
|
8
|
+
return `Hello, ${name}!`;
|
|
9
|
+
}
|
|
10
|
+
export { extractAccountAddress, generateSeedEthereum, generateSeedNonEthereum, isEthereumAddress, generateIconSeed } from "./utils/caip-address.mjs";
|
|
11
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,IAAY;IAC1C,OAAO,UAAU,IAAI,GAAG,CAAC;AAC3B,CAAC;AAED,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,iBAAiB,EACjB,gBAAgB,EACjB,iCAA6B","sourcesContent":["/**\n * Example function that returns a greeting for the given name.\n *\n * @param name - The name to greet.\n * @returns The greeting.\n */\nexport default function greeter(name: string): string {\n return `Hello, ${name}!`;\n}\n\nexport {\n extractAccountAddress,\n generateSeedEthereum,\n generateSeedNonEthereum,\n isEthereumAddress,\n generateIconSeed,\n} from './utils/caip-address';\n"]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateIconSeed = exports.isEthereumAddress = exports.generateSeedNonEthereum = exports.generateSeedEthereum = exports.extractAccountAddress = void 0;
|
|
4
|
+
const utils_1 = require("@metamask/utils");
|
|
5
|
+
/**
|
|
6
|
+
* Extracts the account address from a CAIP-10 formatted address string.
|
|
7
|
+
*
|
|
8
|
+
* For CAIP-10 addresses like "eip155:1:0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8",
|
|
9
|
+
* this returns just the address part: "0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8".
|
|
10
|
+
*
|
|
11
|
+
* This ensures that both legacy addresses and CAIP-10 addresses generate
|
|
12
|
+
* the same icon, regardless of network specification.
|
|
13
|
+
*
|
|
14
|
+
* @param address - The address string (either legacy format or CAIP-10)
|
|
15
|
+
* @returns The extracted account address
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* extractAccountAddress('0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8')
|
|
19
|
+
* Returns: '0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8'
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* extractAccountAddress('eip155:1:0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8')
|
|
23
|
+
* Returns: '0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8'
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* extractAccountAddress('solana:mainnet:4Nd1m3NnENa8h8Xte1Xr7s9jcvKqqm21z3FvY9hKg4s7')
|
|
27
|
+
* Returns: '4Nd1m3NnENa8h8Xte1Xr7s9jcvKqqm21z3FvY9hKg4s7'
|
|
28
|
+
*/
|
|
29
|
+
function extractAccountAddress(address) {
|
|
30
|
+
try {
|
|
31
|
+
// Try to parse as CAIP-10 first
|
|
32
|
+
if ((0, utils_1.isCaipAccountId)(address)) {
|
|
33
|
+
const parsed = (0, utils_1.parseCaipAccountId)(address);
|
|
34
|
+
return parsed.address;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// If parsing fails, fall through to return original address
|
|
39
|
+
}
|
|
40
|
+
// Return the address as-is if it's not CAIP-10 format
|
|
41
|
+
return address;
|
|
42
|
+
}
|
|
43
|
+
exports.extractAccountAddress = extractAccountAddress;
|
|
44
|
+
/**
|
|
45
|
+
* Generates a numeric seed for Ethereum (eip155) addresses.
|
|
46
|
+
*
|
|
47
|
+
* @param address - The Ethereum address to generate a seed from
|
|
48
|
+
* @returns A numeric seed for icon generation
|
|
49
|
+
*/
|
|
50
|
+
function generateSeedEthereum(address) {
|
|
51
|
+
// Parse the first 8 chars of the address after '0x'
|
|
52
|
+
const addr = address.slice(2, 10);
|
|
53
|
+
return parseInt(addr, 16);
|
|
54
|
+
}
|
|
55
|
+
exports.generateSeedEthereum = generateSeedEthereum;
|
|
56
|
+
/**
|
|
57
|
+
* Generates a byte-array seed for non-Ethereum addresses (Solana, Bitcoin, etc.).
|
|
58
|
+
*
|
|
59
|
+
* @param address - The address to generate a byte array seed from
|
|
60
|
+
* @returns An array of numbers representing the bytes of the address
|
|
61
|
+
*/
|
|
62
|
+
function generateSeedNonEthereum(address) {
|
|
63
|
+
return Array.from((0, utils_1.stringToBytes)(address.normalize('NFKC').toLowerCase()));
|
|
64
|
+
}
|
|
65
|
+
exports.generateSeedNonEthereum = generateSeedNonEthereum;
|
|
66
|
+
/**
|
|
67
|
+
* Determines if an address is Ethereum format (starts with 0x).
|
|
68
|
+
*
|
|
69
|
+
* @param address - The address to check
|
|
70
|
+
* @returns True if Ethereum format, false otherwise
|
|
71
|
+
*/
|
|
72
|
+
function isEthereumAddress(address) {
|
|
73
|
+
return address.startsWith('0x');
|
|
74
|
+
}
|
|
75
|
+
exports.isEthereumAddress = isEthereumAddress;
|
|
76
|
+
/**
|
|
77
|
+
* Generates an appropriate seed for icon generation based on address format.
|
|
78
|
+
* Ethereum addresses (0x prefix) use hex parsing, others use byte array.
|
|
79
|
+
*
|
|
80
|
+
* @param address - The address to generate a seed from (should be extracted first)
|
|
81
|
+
* @returns A seed for icon generation (number for Ethereum, number[] for others)
|
|
82
|
+
*/
|
|
83
|
+
function generateIconSeed(address) {
|
|
84
|
+
return isEthereumAddress(address)
|
|
85
|
+
? generateSeedEthereum(address)
|
|
86
|
+
: generateSeedNonEthereum(address);
|
|
87
|
+
}
|
|
88
|
+
exports.generateIconSeed = generateIconSeed;
|
|
89
|
+
//# sourceMappingURL=caip-address.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"caip-address.cjs","sourceRoot":"","sources":["../../src/utils/caip-address.ts"],"names":[],"mappings":";;;AAAA,2CAIyB;AAEzB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAgB,qBAAqB,CAAC,OAAe;IACnD,IAAI;QACF,gCAAgC;QAChC,IAAI,IAAA,uBAAe,EAAC,OAAO,CAAC,EAAE;YAC5B,MAAM,MAAM,GAAG,IAAA,0BAAkB,EAAC,OAAO,CAAC,CAAC;YAC3C,OAAO,MAAM,CAAC,OAAO,CAAC;SACvB;KACF;IAAC,MAAM;QACN,4DAA4D;KAC7D;IAED,sDAAsD;IACtD,OAAO,OAAO,CAAC;AACjB,CAAC;AAbD,sDAaC;AAED;;;;;GAKG;AACH,SAAgB,oBAAoB,CAAC,OAAe;IAClD,oDAAoD;IACpD,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAClC,OAAO,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAC5B,CAAC;AAJD,oDAIC;AAED;;;;;GAKG;AACH,SAAgB,uBAAuB,CAAC,OAAe;IACrD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAA,qBAAa,EAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;AAC5E,CAAC;AAFD,0DAEC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,OAAe;IAC/C,OAAO,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC;AAFD,8CAEC;AAED;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAAC,OAAe;IAC9C,OAAO,iBAAiB,CAAC,OAAO,CAAC;QAC/B,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC;QAC/B,CAAC,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC;AAJD,4CAIC","sourcesContent":["import {\n parseCaipAccountId,\n isCaipAccountId,\n stringToBytes,\n} from '@metamask/utils';\n\n/**\n * Extracts the account address from a CAIP-10 formatted address string.\n *\n * For CAIP-10 addresses like \"eip155:1:0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8\",\n * this returns just the address part: \"0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8\".\n *\n * This ensures that both legacy addresses and CAIP-10 addresses generate\n * the same icon, regardless of network specification.\n *\n * @param address - The address string (either legacy format or CAIP-10)\n * @returns The extracted account address\n *\n * @example\n * extractAccountAddress('0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8')\n * Returns: '0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8'\n *\n * @example\n * extractAccountAddress('eip155:1:0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8')\n * Returns: '0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8'\n *\n * @example\n * extractAccountAddress('solana:mainnet:4Nd1m3NnENa8h8Xte1Xr7s9jcvKqqm21z3FvY9hKg4s7')\n * Returns: '4Nd1m3NnENa8h8Xte1Xr7s9jcvKqqm21z3FvY9hKg4s7'\n */\nexport function extractAccountAddress(address: string): string {\n try {\n // Try to parse as CAIP-10 first\n if (isCaipAccountId(address)) {\n const parsed = parseCaipAccountId(address);\n return parsed.address;\n }\n } catch {\n // If parsing fails, fall through to return original address\n }\n\n // Return the address as-is if it's not CAIP-10 format\n return address;\n}\n\n/**\n * Generates a numeric seed for Ethereum (eip155) addresses.\n *\n * @param address - The Ethereum address to generate a seed from\n * @returns A numeric seed for icon generation\n */\nexport function generateSeedEthereum(address: string): number {\n // Parse the first 8 chars of the address after '0x'\n const addr = address.slice(2, 10);\n return parseInt(addr, 16);\n}\n\n/**\n * Generates a byte-array seed for non-Ethereum addresses (Solana, Bitcoin, etc.).\n *\n * @param address - The address to generate a byte array seed from\n * @returns An array of numbers representing the bytes of the address\n */\nexport function generateSeedNonEthereum(address: string): number[] {\n return Array.from(stringToBytes(address.normalize('NFKC').toLowerCase()));\n}\n\n/**\n * Determines if an address is Ethereum format (starts with 0x).\n *\n * @param address - The address to check\n * @returns True if Ethereum format, false otherwise\n */\nexport function isEthereumAddress(address: string): boolean {\n return address.startsWith('0x');\n}\n\n/**\n * Generates an appropriate seed for icon generation based on address format.\n * Ethereum addresses (0x prefix) use hex parsing, others use byte array.\n *\n * @param address - The address to generate a seed from (should be extracted first)\n * @returns A seed for icon generation (number for Ethereum, number[] for others)\n */\nexport function generateIconSeed(address: string): number | number[] {\n return isEthereumAddress(address)\n ? generateSeedEthereum(address)\n : generateSeedNonEthereum(address);\n}\n"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the account address from a CAIP-10 formatted address string.
|
|
3
|
+
*
|
|
4
|
+
* For CAIP-10 addresses like "eip155:1:0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8",
|
|
5
|
+
* this returns just the address part: "0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8".
|
|
6
|
+
*
|
|
7
|
+
* This ensures that both legacy addresses and CAIP-10 addresses generate
|
|
8
|
+
* the same icon, regardless of network specification.
|
|
9
|
+
*
|
|
10
|
+
* @param address - The address string (either legacy format or CAIP-10)
|
|
11
|
+
* @returns The extracted account address
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* extractAccountAddress('0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8')
|
|
15
|
+
* Returns: '0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8'
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* extractAccountAddress('eip155:1:0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8')
|
|
19
|
+
* Returns: '0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8'
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* extractAccountAddress('solana:mainnet:4Nd1m3NnENa8h8Xte1Xr7s9jcvKqqm21z3FvY9hKg4s7')
|
|
23
|
+
* Returns: '4Nd1m3NnENa8h8Xte1Xr7s9jcvKqqm21z3FvY9hKg4s7'
|
|
24
|
+
*/
|
|
25
|
+
export declare function extractAccountAddress(address: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Generates a numeric seed for Ethereum (eip155) addresses.
|
|
28
|
+
*
|
|
29
|
+
* @param address - The Ethereum address to generate a seed from
|
|
30
|
+
* @returns A numeric seed for icon generation
|
|
31
|
+
*/
|
|
32
|
+
export declare function generateSeedEthereum(address: string): number;
|
|
33
|
+
/**
|
|
34
|
+
* Generates a byte-array seed for non-Ethereum addresses (Solana, Bitcoin, etc.).
|
|
35
|
+
*
|
|
36
|
+
* @param address - The address to generate a byte array seed from
|
|
37
|
+
* @returns An array of numbers representing the bytes of the address
|
|
38
|
+
*/
|
|
39
|
+
export declare function generateSeedNonEthereum(address: string): number[];
|
|
40
|
+
/**
|
|
41
|
+
* Determines if an address is Ethereum format (starts with 0x).
|
|
42
|
+
*
|
|
43
|
+
* @param address - The address to check
|
|
44
|
+
* @returns True if Ethereum format, false otherwise
|
|
45
|
+
*/
|
|
46
|
+
export declare function isEthereumAddress(address: string): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Generates an appropriate seed for icon generation based on address format.
|
|
49
|
+
* Ethereum addresses (0x prefix) use hex parsing, others use byte array.
|
|
50
|
+
*
|
|
51
|
+
* @param address - The address to generate a seed from (should be extracted first)
|
|
52
|
+
* @returns A seed for icon generation (number for Ethereum, number[] for others)
|
|
53
|
+
*/
|
|
54
|
+
export declare function generateIconSeed(address: string): number | number[];
|
|
55
|
+
//# sourceMappingURL=caip-address.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"caip-address.d.cts","sourceRoot":"","sources":["../../src/utils/caip-address.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAa7D;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAI5D;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAEjE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAInE"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the account address from a CAIP-10 formatted address string.
|
|
3
|
+
*
|
|
4
|
+
* For CAIP-10 addresses like "eip155:1:0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8",
|
|
5
|
+
* this returns just the address part: "0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8".
|
|
6
|
+
*
|
|
7
|
+
* This ensures that both legacy addresses and CAIP-10 addresses generate
|
|
8
|
+
* the same icon, regardless of network specification.
|
|
9
|
+
*
|
|
10
|
+
* @param address - The address string (either legacy format or CAIP-10)
|
|
11
|
+
* @returns The extracted account address
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* extractAccountAddress('0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8')
|
|
15
|
+
* Returns: '0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8'
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* extractAccountAddress('eip155:1:0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8')
|
|
19
|
+
* Returns: '0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8'
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* extractAccountAddress('solana:mainnet:4Nd1m3NnENa8h8Xte1Xr7s9jcvKqqm21z3FvY9hKg4s7')
|
|
23
|
+
* Returns: '4Nd1m3NnENa8h8Xte1Xr7s9jcvKqqm21z3FvY9hKg4s7'
|
|
24
|
+
*/
|
|
25
|
+
export declare function extractAccountAddress(address: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Generates a numeric seed for Ethereum (eip155) addresses.
|
|
28
|
+
*
|
|
29
|
+
* @param address - The Ethereum address to generate a seed from
|
|
30
|
+
* @returns A numeric seed for icon generation
|
|
31
|
+
*/
|
|
32
|
+
export declare function generateSeedEthereum(address: string): number;
|
|
33
|
+
/**
|
|
34
|
+
* Generates a byte-array seed for non-Ethereum addresses (Solana, Bitcoin, etc.).
|
|
35
|
+
*
|
|
36
|
+
* @param address - The address to generate a byte array seed from
|
|
37
|
+
* @returns An array of numbers representing the bytes of the address
|
|
38
|
+
*/
|
|
39
|
+
export declare function generateSeedNonEthereum(address: string): number[];
|
|
40
|
+
/**
|
|
41
|
+
* Determines if an address is Ethereum format (starts with 0x).
|
|
42
|
+
*
|
|
43
|
+
* @param address - The address to check
|
|
44
|
+
* @returns True if Ethereum format, false otherwise
|
|
45
|
+
*/
|
|
46
|
+
export declare function isEthereumAddress(address: string): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Generates an appropriate seed for icon generation based on address format.
|
|
49
|
+
* Ethereum addresses (0x prefix) use hex parsing, others use byte array.
|
|
50
|
+
*
|
|
51
|
+
* @param address - The address to generate a seed from (should be extracted first)
|
|
52
|
+
* @returns A seed for icon generation (number for Ethereum, number[] for others)
|
|
53
|
+
*/
|
|
54
|
+
export declare function generateIconSeed(address: string): number | number[];
|
|
55
|
+
//# sourceMappingURL=caip-address.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"caip-address.d.mts","sourceRoot":"","sources":["../../src/utils/caip-address.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAa7D;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAI5D;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAEjE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAInE"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { parseCaipAccountId, isCaipAccountId, stringToBytes } from "@metamask/utils";
|
|
2
|
+
/**
|
|
3
|
+
* Extracts the account address from a CAIP-10 formatted address string.
|
|
4
|
+
*
|
|
5
|
+
* For CAIP-10 addresses like "eip155:1:0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8",
|
|
6
|
+
* this returns just the address part: "0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8".
|
|
7
|
+
*
|
|
8
|
+
* This ensures that both legacy addresses and CAIP-10 addresses generate
|
|
9
|
+
* the same icon, regardless of network specification.
|
|
10
|
+
*
|
|
11
|
+
* @param address - The address string (either legacy format or CAIP-10)
|
|
12
|
+
* @returns The extracted account address
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* extractAccountAddress('0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8')
|
|
16
|
+
* Returns: '0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8'
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* extractAccountAddress('eip155:1:0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8')
|
|
20
|
+
* Returns: '0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8'
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* extractAccountAddress('solana:mainnet:4Nd1m3NnENa8h8Xte1Xr7s9jcvKqqm21z3FvY9hKg4s7')
|
|
24
|
+
* Returns: '4Nd1m3NnENa8h8Xte1Xr7s9jcvKqqm21z3FvY9hKg4s7'
|
|
25
|
+
*/
|
|
26
|
+
export function extractAccountAddress(address) {
|
|
27
|
+
try {
|
|
28
|
+
// Try to parse as CAIP-10 first
|
|
29
|
+
if (isCaipAccountId(address)) {
|
|
30
|
+
const parsed = parseCaipAccountId(address);
|
|
31
|
+
return parsed.address;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// If parsing fails, fall through to return original address
|
|
36
|
+
}
|
|
37
|
+
// Return the address as-is if it's not CAIP-10 format
|
|
38
|
+
return address;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Generates a numeric seed for Ethereum (eip155) addresses.
|
|
42
|
+
*
|
|
43
|
+
* @param address - The Ethereum address to generate a seed from
|
|
44
|
+
* @returns A numeric seed for icon generation
|
|
45
|
+
*/
|
|
46
|
+
export function generateSeedEthereum(address) {
|
|
47
|
+
// Parse the first 8 chars of the address after '0x'
|
|
48
|
+
const addr = address.slice(2, 10);
|
|
49
|
+
return parseInt(addr, 16);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Generates a byte-array seed for non-Ethereum addresses (Solana, Bitcoin, etc.).
|
|
53
|
+
*
|
|
54
|
+
* @param address - The address to generate a byte array seed from
|
|
55
|
+
* @returns An array of numbers representing the bytes of the address
|
|
56
|
+
*/
|
|
57
|
+
export function generateSeedNonEthereum(address) {
|
|
58
|
+
return Array.from(stringToBytes(address.normalize('NFKC').toLowerCase()));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Determines if an address is Ethereum format (starts with 0x).
|
|
62
|
+
*
|
|
63
|
+
* @param address - The address to check
|
|
64
|
+
* @returns True if Ethereum format, false otherwise
|
|
65
|
+
*/
|
|
66
|
+
export function isEthereumAddress(address) {
|
|
67
|
+
return address.startsWith('0x');
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Generates an appropriate seed for icon generation based on address format.
|
|
71
|
+
* Ethereum addresses (0x prefix) use hex parsing, others use byte array.
|
|
72
|
+
*
|
|
73
|
+
* @param address - The address to generate a seed from (should be extracted first)
|
|
74
|
+
* @returns A seed for icon generation (number for Ethereum, number[] for others)
|
|
75
|
+
*/
|
|
76
|
+
export function generateIconSeed(address) {
|
|
77
|
+
return isEthereumAddress(address)
|
|
78
|
+
? generateSeedEthereum(address)
|
|
79
|
+
: generateSeedNonEthereum(address);
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=caip-address.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"caip-address.mjs","sourceRoot":"","sources":["../../src/utils/caip-address.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,aAAa,EACd,wBAAwB;AAEzB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAe;IACnD,IAAI;QACF,gCAAgC;QAChC,IAAI,eAAe,CAAC,OAAO,CAAC,EAAE;YAC5B,MAAM,MAAM,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;YAC3C,OAAO,MAAM,CAAC,OAAO,CAAC;SACvB;KACF;IAAC,MAAM;QACN,4DAA4D;KAC7D;IAED,sDAAsD;IACtD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAe;IAClD,oDAAoD;IACpD,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAClC,OAAO,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAAe;IACrD,OAAO,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,OAAO,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC9C,OAAO,iBAAiB,CAAC,OAAO,CAAC;QAC/B,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC;QAC/B,CAAC,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import {\n parseCaipAccountId,\n isCaipAccountId,\n stringToBytes,\n} from '@metamask/utils';\n\n/**\n * Extracts the account address from a CAIP-10 formatted address string.\n *\n * For CAIP-10 addresses like \"eip155:1:0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8\",\n * this returns just the address part: \"0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8\".\n *\n * This ensures that both legacy addresses and CAIP-10 addresses generate\n * the same icon, regardless of network specification.\n *\n * @param address - The address string (either legacy format or CAIP-10)\n * @returns The extracted account address\n *\n * @example\n * extractAccountAddress('0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8')\n * Returns: '0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8'\n *\n * @example\n * extractAccountAddress('eip155:1:0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8')\n * Returns: '0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8'\n *\n * @example\n * extractAccountAddress('solana:mainnet:4Nd1m3NnENa8h8Xte1Xr7s9jcvKqqm21z3FvY9hKg4s7')\n * Returns: '4Nd1m3NnENa8h8Xte1Xr7s9jcvKqqm21z3FvY9hKg4s7'\n */\nexport function extractAccountAddress(address: string): string {\n try {\n // Try to parse as CAIP-10 first\n if (isCaipAccountId(address)) {\n const parsed = parseCaipAccountId(address);\n return parsed.address;\n }\n } catch {\n // If parsing fails, fall through to return original address\n }\n\n // Return the address as-is if it's not CAIP-10 format\n return address;\n}\n\n/**\n * Generates a numeric seed for Ethereum (eip155) addresses.\n *\n * @param address - The Ethereum address to generate a seed from\n * @returns A numeric seed for icon generation\n */\nexport function generateSeedEthereum(address: string): number {\n // Parse the first 8 chars of the address after '0x'\n const addr = address.slice(2, 10);\n return parseInt(addr, 16);\n}\n\n/**\n * Generates a byte-array seed for non-Ethereum addresses (Solana, Bitcoin, etc.).\n *\n * @param address - The address to generate a byte array seed from\n * @returns An array of numbers representing the bytes of the address\n */\nexport function generateSeedNonEthereum(address: string): number[] {\n return Array.from(stringToBytes(address.normalize('NFKC').toLowerCase()));\n}\n\n/**\n * Determines if an address is Ethereum format (starts with 0x).\n *\n * @param address - The address to check\n * @returns True if Ethereum format, false otherwise\n */\nexport function isEthereumAddress(address: string): boolean {\n return address.startsWith('0x');\n}\n\n/**\n * Generates an appropriate seed for icon generation based on address format.\n * Ethereum addresses (0x prefix) use hex parsing, others use byte array.\n *\n * @param address - The address to generate a seed from (should be extracted first)\n * @returns A seed for icon generation (number for Ethereum, number[] for others)\n */\nexport function generateIconSeed(address: string): number | number[] {\n return isEthereumAddress(address)\n ? generateSeedEthereum(address)\n : generateSeedNonEthereum(address);\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@metamask-previews/design-system-shared",
|
|
3
|
+
"version": "0.0.0-preview.374d60e",
|
|
4
|
+
"description": "Shared types for design system libraries",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"MetaMask",
|
|
7
|
+
"Ethereum"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://github.com/MetaMask/metamask-design-system/tree/main/packages/design-system-shared#readme",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/MetaMask/metamask-design-system/issues"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/MetaMask/metamask-design-system.git"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/index.d.mts",
|
|
23
|
+
"default": "./dist/index.mjs"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/index.d.cts",
|
|
27
|
+
"default": "./dist/index.cjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"main": "./dist/index.cjs",
|
|
33
|
+
"types": "./dist/index.d.cts",
|
|
34
|
+
"files": [
|
|
35
|
+
"dist/"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
|
|
39
|
+
"changelog:update": "../../scripts/update-changelog.sh @metamask/design-system-shared",
|
|
40
|
+
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/design-system-shared",
|
|
41
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
42
|
+
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
43
|
+
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
|
|
44
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch",
|
|
45
|
+
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
46
|
+
"publish:preview": "yarn npm publish --tag preview"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@metamask/utils": "^11.7.0"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@metamask/auto-changelog": "^5.0.2",
|
|
53
|
+
"@ts-bridge/cli": "^0.6.3",
|
|
54
|
+
"@types/jest": "^27.4.1",
|
|
55
|
+
"deepmerge": "^4.2.2",
|
|
56
|
+
"jest": "^29.7.0",
|
|
57
|
+
"ts-jest": "^29.2.5",
|
|
58
|
+
"typescript": "~5.2.2"
|
|
59
|
+
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": "^18.18 || >=20"
|
|
62
|
+
},
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"access": "public",
|
|
65
|
+
"registry": "https://registry.npmjs.org/"
|
|
66
|
+
}
|
|
67
|
+
}
|