@shapeshiftoss/caip 1.5.1 → 1.6.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/dist/caip10/caip10.d.ts +15 -0
- package/dist/caip10/caip10.js +40 -0
- package/dist/caip2/caip2.d.ts +2 -0
- package/dist/caip2/caip2.js +29 -3
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -3
- package/package.json +1 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CAIP2 } from './../caip2/caip2';
|
|
2
|
+
export declare type CAIP10 = string;
|
|
3
|
+
declare type ToCAIP19Args = {
|
|
4
|
+
caip2: CAIP2;
|
|
5
|
+
account: string;
|
|
6
|
+
};
|
|
7
|
+
declare type ToCAIP10 = (args: ToCAIP19Args) => string;
|
|
8
|
+
export declare const toCAIP10: ToCAIP10;
|
|
9
|
+
declare type FromCAIP10Return = {
|
|
10
|
+
caip2: string;
|
|
11
|
+
account: string;
|
|
12
|
+
};
|
|
13
|
+
declare type FromCAIP10 = (caip10: string) => FromCAIP10Return;
|
|
14
|
+
export declare const fromCAIP10: FromCAIP10;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fromCAIP10 = exports.toCAIP10 = void 0;
|
|
4
|
+
const caip2_1 = require("./../caip2/caip2");
|
|
5
|
+
const toCAIP10 = ({ caip2, account }) => {
|
|
6
|
+
if (!(0, caip2_1.isCAIP2)(caip2)) {
|
|
7
|
+
throw new Error(`toCAIP10: invalid caip2 ${caip2}`);
|
|
8
|
+
}
|
|
9
|
+
if (!account) {
|
|
10
|
+
throw new Error(`toCAIP10: account is required`);
|
|
11
|
+
}
|
|
12
|
+
const [namespace] = caip2.split(':');
|
|
13
|
+
// we lowercase eth accounts as per the draft spec
|
|
14
|
+
// it's not explicit, but cHecKsUM can be recovered from lowercase eth accounts
|
|
15
|
+
// we don't lowercase bitcoin addresses as they'll fail checksum
|
|
16
|
+
const outputAccount = namespace === caip2_1.ChainNamespace.Ethereum ? account.toLowerCase() : account;
|
|
17
|
+
return `${caip2}:${outputAccount}`;
|
|
18
|
+
};
|
|
19
|
+
exports.toCAIP10 = toCAIP10;
|
|
20
|
+
const fromCAIP10 = (caip10) => {
|
|
21
|
+
const parts = caip10.split(':');
|
|
22
|
+
if (parts.length !== 3) {
|
|
23
|
+
throw new Error(`fromCAIP10: invalid caip10 ${caip10}`);
|
|
24
|
+
}
|
|
25
|
+
const caip2 = parts.slice(0, 2).join(':');
|
|
26
|
+
if (!(0, caip2_1.isCAIP2)(caip2)) {
|
|
27
|
+
throw new Error(`fromCAIP10: invalid caip2 ${caip2}`);
|
|
28
|
+
}
|
|
29
|
+
const account = parts[2];
|
|
30
|
+
if (!account) {
|
|
31
|
+
throw new Error(`fromCAIP10: account required`);
|
|
32
|
+
}
|
|
33
|
+
const [namespace] = caip2.split(':');
|
|
34
|
+
// we lowercase eth accounts as per the draft spec
|
|
35
|
+
// it's not explicit, but cHecKsUM can be recovered from lowercase eth accounts
|
|
36
|
+
// we don't lowercase bitcoin addresses as they'll fail checksum
|
|
37
|
+
const outputAccount = namespace === caip2_1.ChainNamespace.Ethereum ? account.toLowerCase() : account;
|
|
38
|
+
return { caip2, account: outputAccount };
|
|
39
|
+
};
|
|
40
|
+
exports.fromCAIP10 = fromCAIP10;
|
package/dist/caip2/caip2.d.ts
CHANGED
package/dist/caip2/caip2.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.fromCAIP2 = exports.toCAIP2 = exports.ChainReference = exports.ChainNamespace = void 0;
|
|
4
|
+
exports.isCAIP2 = exports.fromCAIP2 = exports.toCAIP2 = exports.ChainReference = exports.ChainNamespace = void 0;
|
|
5
5
|
const types_1 = require("@shapeshiftoss/types");
|
|
6
6
|
var ChainNamespace;
|
|
7
7
|
(function (ChainNamespace) {
|
|
@@ -73,7 +73,7 @@ const fromCAIP2 = (caip2) => {
|
|
|
73
73
|
throw new Error(`fromCAIP19: error parsing caip19, chain: ${c}, network: ${n}`);
|
|
74
74
|
}
|
|
75
75
|
switch (c) {
|
|
76
|
-
case
|
|
76
|
+
case ChainNamespace.Ethereum: {
|
|
77
77
|
const chain = types_1.ChainTypes.Ethereum;
|
|
78
78
|
switch (n) {
|
|
79
79
|
case ChainReference.EthereumMainnet: {
|
|
@@ -93,7 +93,7 @@ const fromCAIP2 = (caip2) => {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
case
|
|
96
|
+
case ChainNamespace.Bitcoin: {
|
|
97
97
|
const chain = types_1.ChainTypes.Bitcoin;
|
|
98
98
|
switch (n) {
|
|
99
99
|
case ChainReference.BitcoinMainnet: {
|
|
@@ -113,3 +113,29 @@ const fromCAIP2 = (caip2) => {
|
|
|
113
113
|
throw new Error(`fromCAIP19: unsupported chain: ${c}`);
|
|
114
114
|
};
|
|
115
115
|
exports.fromCAIP2 = fromCAIP2;
|
|
116
|
+
const isCAIP2 = (caip2) => {
|
|
117
|
+
const [c, n] = caip2.split(':');
|
|
118
|
+
if (!(c && n)) {
|
|
119
|
+
throw new Error(`isCAIP2: error parsing caip19, chain: ${c}, network: ${n}`);
|
|
120
|
+
}
|
|
121
|
+
switch (c) {
|
|
122
|
+
case ChainNamespace.Ethereum: {
|
|
123
|
+
switch (n) {
|
|
124
|
+
case ChainReference.EthereumMainnet:
|
|
125
|
+
case ChainReference.EthereumRopsten:
|
|
126
|
+
case ChainReference.EthereumRinkeby:
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
case ChainNamespace.Bitcoin: {
|
|
132
|
+
switch (n) {
|
|
133
|
+
case ChainReference.BitcoinMainnet:
|
|
134
|
+
case ChainReference.BitcoinTestnet:
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
throw new Error(`isCAIP2: invalid caip2 ${caip2}`);
|
|
140
|
+
};
|
|
141
|
+
exports.isCAIP2 = isCAIP2;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as adapters from './adapters/coingecko';
|
|
2
2
|
import * as caip2 from './caip2/caip2';
|
|
3
|
+
import * as caip10 from './caip10/caip10';
|
|
3
4
|
import * as caip19 from './caip19/caip19';
|
|
4
|
-
export { adapters, caip2, caip19 };
|
|
5
|
+
export { adapters, caip2, caip19, caip10 };
|
|
5
6
|
export { CAIP2 } from './caip2/caip2';
|
|
6
|
-
export {
|
|
7
|
+
export { CAIP10 } from './caip10/caip10';
|
|
8
|
+
export { CAIP19 } from './caip19/caip19';
|
package/dist/index.js
CHANGED
|
@@ -19,12 +19,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.
|
|
22
|
+
exports.caip10 = exports.caip19 = exports.caip2 = exports.adapters = void 0;
|
|
23
23
|
const adapters = __importStar(require("./adapters/coingecko"));
|
|
24
24
|
exports.adapters = adapters;
|
|
25
25
|
const caip2 = __importStar(require("./caip2/caip2"));
|
|
26
26
|
exports.caip2 = caip2;
|
|
27
|
+
const caip10 = __importStar(require("./caip10/caip10"));
|
|
28
|
+
exports.caip10 = caip10;
|
|
27
29
|
const caip19 = __importStar(require("./caip19/caip19"));
|
|
28
30
|
exports.caip19 = caip19;
|
|
29
|
-
var caip19_1 = require("./caip19/caip19");
|
|
30
|
-
Object.defineProperty(exports, "fromCAIP19", { enumerable: true, get: function () { return caip19_1.fromCAIP19; } });
|