@hub3js/starknet 0.0.0-experimental-29a36fc0-20260720
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/actions.d.ts +4 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/after.d.ts +2 -0
- package/dist/after.d.ts.map +1 -0
- package/dist/and.d.ts +3 -0
- package/dist/and.d.ts.map +1 -0
- package/dist/before.d.ts +2 -0
- package/dist/before.d.ts.map +1 -0
- package/dist/builders.d.ts +5 -0
- package/dist/builders.d.ts.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/mod.d.ts +9 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +2 -0
- package/dist/mod.js.map +7 -0
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +7 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +42 -0
- package/readme.md +3 -0
- package/src/actions.ts +19 -0
- package/src/after.ts +3 -0
- package/src/and.ts +5 -0
- package/src/before.ts +3 -0
- package/src/builders.ts +18 -0
- package/src/constants.ts +9 -0
- package/src/mod.ts +9 -0
- package/src/types.ts +18 -0
- package/src/utils.ts +37 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ProviderAPI } from './types.js';
|
|
2
|
+
export declare const recommended: (readonly ["disconnect", typeof import("@hub3js/std/actions").disconnect])[];
|
|
3
|
+
export declare function canEagerConnect(instance: () => ProviderAPI): () => Promise<any>;
|
|
4
|
+
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI9C,eAAO,MAAM,WAAW,8EAA0B,CAAC;AAEnD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,WAAW,sBAY1D"}
|
package/dist/after.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"after.d.ts","sourceRoot":"","sources":["../src/after.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,yFAAwB,CAAC"}
|
package/dist/and.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"and.d.ts","sourceRoot":"","sources":["../src/and.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qCAAqC,EAAE,MAAM,uBAAuB,CAAC;AAE9E,eAAO,MAAM,WAAW,wEAEvB,CAAC"}
|
package/dist/before.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"before.d.ts","sourceRoot":"","sources":["../src/before.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,iFAAyB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { StarknetActions } from './types.js';
|
|
2
|
+
import { ActionBuilder } from '@hub3js/core';
|
|
3
|
+
export declare const connect: () => ActionBuilder<StarknetActions, "connect">;
|
|
4
|
+
export declare const canEagerConnect: () => ActionBuilder<StarknetActions, "canEagerConnect">;
|
|
5
|
+
//# sourceMappingURL=builders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAQ7C,eAAO,MAAM,OAAO,iDAIc,CAAC;AAEnC,eAAO,MAAM,eAAe,yDAC8C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,cAAc,aAAa,CAAC;AACzC,eAAO,MAAM,sBAAsB,YAAY,CAAC;AAChD,eAAO,MAAM,QAAQ,WAAW,CAAC"}
|
package/dist/mod.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * as actions from './actions.js';
|
|
2
|
+
export * as after from './after.js';
|
|
3
|
+
export * as and from './and.js';
|
|
4
|
+
export * as before from './before.js';
|
|
5
|
+
export * as builders from './builders.js';
|
|
6
|
+
export * as utils from './utils.js';
|
|
7
|
+
export type { ProviderAPI, StarknetActions } from './types.js';
|
|
8
|
+
export { CAIP_NAMESPACE, CAIP_STARKNET_CHAIN_ID } from './constants.js';
|
|
9
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAEpC,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/mod.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var a=Object.defineProperty;var e=(o,t)=>a(o,"name",{value:t,configurable:!0});var n=(o,t)=>{for(var r in t)a(o,r,{get:t[r],enumerable:!0})};var i={};n(i,{canEagerConnect:()=>x,recommended:()=>P});import{recommendedActions as C}from"@hub3js/std/actions";var P=[...C];function x(o){return async()=>{let t=o();if(!t)throw new Error("Trying to eagerly connect to your Starknet wallet, but seems its instance is not available.");return t.isPreauthorized()}}e(x,"canEagerConnect");var m={};n(m,{recommended:()=>y});import{afterRecommended as S}from"@hub3js/std/operators";var y=[...S];var p={};n(p,{recommended:()=>_});import{connectAndUpdateStateForSingleNetwork as N}from"@hub3js/std/operators";var _=[["connect",N]];var A={};n(A,{recommended:()=>E});import{beforeRecommended as g}from"@hub3js/std/operators";var E=[...g];var f={};n(f,{canEagerConnect:()=>T,connect:()=>w});import{ActionBuilder as d}from"@hub3js/core";import{connectAndUpdateStateForSingleNetwork as l,intoConnecting as k,intoConnectionFinished as b}from"@hub3js/std/operators";var w=e(()=>new d("connect").and(l).before(k).after(b),"connect"),T=e(()=>new d("canEagerConnect"),"canEagerConnect");var u={};n(u,{formatAccountsToCAIP:()=>j,getAccounts:()=>R});import{AccountId as h}from"caip";var c="starknet",s="SN_MAIN",I="SOLANA";async function R(o){let t=await o.connect();return{accounts:[t?t.publicKey.toString():o.publicKey.toString()],chainId:I}}e(R,"getAccounts");function j(o){return o.map(t=>h.format({address:t.toString(),chainId:{namespace:c,reference:s}}))}e(j,"formatAccountsToCAIP");export{c as CAIP_NAMESPACE,s as CAIP_STARKNET_CHAIN_ID,i as actions,m as after,p as and,A as before,f as builders,u as utils};
|
|
2
|
+
//# sourceMappingURL=mod.js.map
|
package/dist/mod.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/actions.ts", "../src/after.ts", "../src/and.ts", "../src/before.ts", "../src/builders.ts", "../src/utils.ts", "../src/constants.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ProviderAPI } from './types.js';\n\nimport { recommendedActions } from '@hub3js/std/actions';\n\nexport const recommended = [...recommendedActions];\n\nexport function canEagerConnect(instance: () => ProviderAPI) {\n return async () => {\n const starknetInstance = instance();\n\n if (!starknetInstance) {\n throw new Error(\n 'Trying to eagerly connect to your Starknet wallet, but seems its instance is not available.',\n );\n }\n\n return starknetInstance.isPreauthorized();\n };\n}\n", "import { afterRecommended } from '@hub3js/std/operators';\n\nexport const recommended = [...afterRecommended];\n", "import { connectAndUpdateStateForSingleNetwork } from '@hub3js/std/operators';\n\nexport const recommended = [\n ['connect', connectAndUpdateStateForSingleNetwork] as const,\n];\n", "import { beforeRecommended } from '@hub3js/std/operators';\n\nexport const recommended = [...beforeRecommended];\n", "import type { StarknetActions } from './types.js';\n\nimport { ActionBuilder } from '@hub3js/core';\nimport {\n connectAndUpdateStateForSingleNetwork,\n intoConnecting,\n intoConnectionFinished,\n} from '@hub3js/std/operators';\n\n// Actions\nexport const connect = () =>\n new ActionBuilder<StarknetActions, 'connect'>('connect')\n .and(connectAndUpdateStateForSingleNetwork)\n .before(intoConnecting)\n .after(intoConnectionFinished);\n\nexport const canEagerConnect = () =>\n new ActionBuilder<StarknetActions, 'canEagerConnect'>('canEagerConnect');\n", "import type { ProviderAPI } from './types.js';\nimport type { CaipAccount } from '@hub3js/std/types';\n\nimport { AccountId } from 'caip';\n\nimport {\n CAIP_NAMESPACE,\n CAIP_STARKNET_CHAIN_ID,\n CHAIN_ID,\n} from './constants.js';\n\nexport async function getAccounts(provider: ProviderAPI) {\n const starknetResponse = await provider.connect();\n /*\n * Fallback for wallets that return no response on connect.\n */\n const account = starknetResponse\n ? starknetResponse.publicKey.toString()\n : provider.publicKey.toString();\n return {\n accounts: [account],\n chainId: CHAIN_ID,\n };\n}\n\nexport function formatAccountsToCAIP(accounts: string[]) {\n return accounts.map(\n (account) =>\n AccountId.format({\n address: account.toString(),\n chainId: {\n namespace: CAIP_NAMESPACE,\n reference: CAIP_STARKNET_CHAIN_ID,\n },\n }) as CaipAccount,\n );\n}\n", "/*\n * TODO: I couldn't found starknet in caip\n * @see https://namespaces.chainagnostic.org/\n */\n\n// if the value needs to be change make sure you will update mapCaipNamespaceToLegacyNetworkName as well\nexport const CAIP_NAMESPACE = 'starknet';\nexport const CAIP_STARKNET_CHAIN_ID = 'SN_MAIN';\nexport const CHAIN_ID = 'SOLANA';\n"],
|
|
5
|
+
"mappings": "6IAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,gBAAAC,IAEA,OAAS,sBAAAC,MAA0B,sBAE5B,IAAMC,EAAc,CAAC,GAAGC,CAAkB,EAE1C,SAASC,EAAgBC,EAA6B,CAC3D,MAAO,UAAY,CACjB,IAAMC,EAAmBD,EAAS,EAElC,GAAI,CAACC,EACH,MAAM,IAAI,MACR,6FACF,EAGF,OAAOA,EAAiB,gBAAgB,CAC1C,CACF,CAZgBC,EAAAH,EAAA,mBCNhB,IAAAI,EAAA,GAAAC,EAAAD,EAAA,iBAAAE,IAAA,OAAS,oBAAAC,MAAwB,wBAE1B,IAAMD,EAAc,CAAC,GAAGC,CAAgB,ECF/C,IAAAC,EAAA,GAAAC,EAAAD,EAAA,iBAAAE,IAAA,OAAS,yCAAAC,MAA6C,wBAE/C,IAAMD,EAAc,CACzB,CAAC,UAAWC,CAAqC,CACnD,ECJA,IAAAC,EAAA,GAAAC,EAAAD,EAAA,iBAAAE,IAAA,OAAS,qBAAAC,MAAyB,wBAE3B,IAAMD,EAAc,CAAC,GAAGC,CAAiB,ECFhD,IAAAC,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,YAAAC,IAEA,OAAS,iBAAAC,MAAqB,eAC9B,OACE,yCAAAC,EACA,kBAAAC,EACA,0BAAAC,MACK,wBAGA,IAAMC,EAAUC,EAAA,IACrB,IAAIC,EAA0C,SAAS,EACpD,IAAIC,CAAqC,EACzC,OAAOC,CAAc,EACrB,MAAMC,CAAsB,EAJV,WAMVC,EAAkBL,EAAA,IAC7B,IAAIC,EAAkD,iBAAiB,EAD1C,mBChB/B,IAAAK,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,EAAA,gBAAAC,IAGA,OAAS,aAAAC,MAAiB,OCGnB,IAAMC,EAAiB,WACjBC,EAAyB,UACzBC,EAAW,SDGxB,eAAsBC,EAAYC,EAAuB,CACvD,IAAMC,EAAmB,MAAMD,EAAS,QAAQ,EAOhD,MAAO,CACL,SAAU,CAJIC,EACZA,EAAiB,UAAU,SAAS,EACpCD,EAAS,UAAU,SAAS,CAEZ,EAClB,QAASE,CACX,CACF,CAZsBC,EAAAJ,EAAA,eAcf,SAASK,EAAqBC,EAAoB,CACvD,OAAOA,EAAS,IACbC,GACCC,EAAU,OAAO,CACf,QAASD,EAAQ,SAAS,EAC1B,QAAS,CACP,UAAWE,EACX,UAAWC,CACb,CACF,CAAC,CACL,CACF,CAXgBN,EAAAC,EAAA",
|
|
6
|
+
"names": ["actions_exports", "__export", "canEagerConnect", "recommended", "recommendedActions", "recommended", "recommendedActions", "canEagerConnect", "instance", "starknetInstance", "__name", "after_exports", "__export", "recommended", "afterRecommended", "and_exports", "__export", "recommended", "connectAndUpdateStateForSingleNetwork", "before_exports", "__export", "recommended", "beforeRecommended", "builders_exports", "__export", "canEagerConnect", "connect", "ActionBuilder", "connectAndUpdateStateForSingleNetwork", "intoConnecting", "intoConnectionFinished", "connect", "__name", "ActionBuilder", "connectAndUpdateStateForSingleNetwork", "intoConnecting", "intoConnectionFinished", "canEagerConnect", "utils_exports", "__export", "formatAccountsToCAIP", "getAccounts", "AccountId", "CAIP_NAMESPACE", "CAIP_STARKNET_CHAIN_ID", "CHAIN_ID", "getAccounts", "provider", "starknetResponse", "CHAIN_ID", "__name", "formatAccountsToCAIP", "accounts", "account", "AccountId", "CAIP_NAMESPACE", "CAIP_STARKNET_CHAIN_ID"]
|
|
7
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Accounts, AutoImplementedActionsByRecommended, CommonActions } from '@hub3js/std/types';
|
|
2
|
+
export interface StarknetActions extends AutoImplementedActionsByRecommended, CommonActions {
|
|
3
|
+
connect: (options?: ConnectOptions) => Promise<Accounts>;
|
|
4
|
+
canEagerConnect: () => Promise<boolean>;
|
|
5
|
+
}
|
|
6
|
+
export type ProviderAPI = Record<string, any>;
|
|
7
|
+
export type ConnectOptions = {
|
|
8
|
+
derivationPath?: string;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,mCAAmC,EACnC,aAAa,EACd,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,eACf,SAAQ,mCAAmC,EAAE,aAAa;IAC1D,OAAO,EAAE,CAAC,OAAO,CAAC,EAAE,cAAc,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IACzD,eAAe,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;CACzC;AAGD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE9C,MAAM,MAAM,cAAc,GAAG;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ProviderAPI } from './types.js';
|
|
2
|
+
export declare function getAccounts(provider: ProviderAPI): Promise<{
|
|
3
|
+
accounts: any[];
|
|
4
|
+
chainId: string;
|
|
5
|
+
}>;
|
|
6
|
+
export declare function formatAccountsToCAIP(accounts: string[]): `${string}:${string}:${string}`[];
|
|
7
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAW9C,wBAAsB,WAAW,CAAC,QAAQ,EAAE,WAAW;;;GAYtD;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,qCAWtD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hub3js/starknet",
|
|
3
|
+
"version": "0.0.0-experimental-29a36fc0-20260720",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"source": "./src/mod.ts",
|
|
7
|
+
"main": "./dist/mod.js",
|
|
8
|
+
"typings": "./dist/mod.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/mod.d.ts",
|
|
12
|
+
"default": "./dist/mod.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "yarn run rangutopia library build",
|
|
21
|
+
"ts-check": "tsc --declaration --emitDeclarationOnly -p tsconfig.json",
|
|
22
|
+
"clean": "rimraf dist",
|
|
23
|
+
"format": "prettier --write '{.,src}/**/*.{ts,tsx}'",
|
|
24
|
+
"lint": "eslint \"**/*.{ts,tsx}\"",
|
|
25
|
+
"test": "vitest",
|
|
26
|
+
"coverage": "vitest run --coverage"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@hub3js/core": "^0.0.0-experimental-29a36fc0-20260720"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@hub3js/core": "^0.0.0-experimental-29a36fc0-20260720"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@hub3js/std": "^0.0.0-experimental-29a36fc0-20260720",
|
|
36
|
+
"caip": "^1.1.1",
|
|
37
|
+
"rango-types": "^0.5.0"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/readme.md
ADDED
package/src/actions.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ProviderAPI } from './types.js';
|
|
2
|
+
|
|
3
|
+
import { recommendedActions } from '@hub3js/std/actions';
|
|
4
|
+
|
|
5
|
+
export const recommended = [...recommendedActions];
|
|
6
|
+
|
|
7
|
+
export function canEagerConnect(instance: () => ProviderAPI) {
|
|
8
|
+
return async () => {
|
|
9
|
+
const starknetInstance = instance();
|
|
10
|
+
|
|
11
|
+
if (!starknetInstance) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
'Trying to eagerly connect to your Starknet wallet, but seems its instance is not available.',
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return starknetInstance.isPreauthorized();
|
|
18
|
+
};
|
|
19
|
+
}
|
package/src/after.ts
ADDED
package/src/and.ts
ADDED
package/src/before.ts
ADDED
package/src/builders.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { StarknetActions } from './types.js';
|
|
2
|
+
|
|
3
|
+
import { ActionBuilder } from '@hub3js/core';
|
|
4
|
+
import {
|
|
5
|
+
connectAndUpdateStateForSingleNetwork,
|
|
6
|
+
intoConnecting,
|
|
7
|
+
intoConnectionFinished,
|
|
8
|
+
} from '@hub3js/std/operators';
|
|
9
|
+
|
|
10
|
+
// Actions
|
|
11
|
+
export const connect = () =>
|
|
12
|
+
new ActionBuilder<StarknetActions, 'connect'>('connect')
|
|
13
|
+
.and(connectAndUpdateStateForSingleNetwork)
|
|
14
|
+
.before(intoConnecting)
|
|
15
|
+
.after(intoConnectionFinished);
|
|
16
|
+
|
|
17
|
+
export const canEagerConnect = () =>
|
|
18
|
+
new ActionBuilder<StarknetActions, 'canEagerConnect'>('canEagerConnect');
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* TODO: I couldn't found starknet in caip
|
|
3
|
+
* @see https://namespaces.chainagnostic.org/
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// if the value needs to be change make sure you will update mapCaipNamespaceToLegacyNetworkName as well
|
|
7
|
+
export const CAIP_NAMESPACE = 'starknet';
|
|
8
|
+
export const CAIP_STARKNET_CHAIN_ID = 'SN_MAIN';
|
|
9
|
+
export const CHAIN_ID = 'SOLANA';
|
package/src/mod.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * as actions from './actions.js';
|
|
2
|
+
export * as after from './after.js';
|
|
3
|
+
export * as and from './and.js';
|
|
4
|
+
export * as before from './before.js';
|
|
5
|
+
export * as builders from './builders.js';
|
|
6
|
+
export * as utils from './utils.js';
|
|
7
|
+
|
|
8
|
+
export type { ProviderAPI, StarknetActions } from './types.js';
|
|
9
|
+
export { CAIP_NAMESPACE, CAIP_STARKNET_CHAIN_ID } from './constants.js';
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Accounts,
|
|
3
|
+
AutoImplementedActionsByRecommended,
|
|
4
|
+
CommonActions,
|
|
5
|
+
} from '@hub3js/std/types';
|
|
6
|
+
|
|
7
|
+
export interface StarknetActions
|
|
8
|
+
extends AutoImplementedActionsByRecommended, CommonActions {
|
|
9
|
+
connect: (options?: ConnectOptions) => Promise<Accounts>;
|
|
10
|
+
canEagerConnect: () => Promise<boolean>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
export type ProviderAPI = Record<string, any>;
|
|
15
|
+
|
|
16
|
+
export type ConnectOptions = {
|
|
17
|
+
derivationPath?: string;
|
|
18
|
+
};
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ProviderAPI } from './types.js';
|
|
2
|
+
import type { CaipAccount } from '@hub3js/std/types';
|
|
3
|
+
|
|
4
|
+
import { AccountId } from 'caip';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
CAIP_NAMESPACE,
|
|
8
|
+
CAIP_STARKNET_CHAIN_ID,
|
|
9
|
+
CHAIN_ID,
|
|
10
|
+
} from './constants.js';
|
|
11
|
+
|
|
12
|
+
export async function getAccounts(provider: ProviderAPI) {
|
|
13
|
+
const starknetResponse = await provider.connect();
|
|
14
|
+
/*
|
|
15
|
+
* Fallback for wallets that return no response on connect.
|
|
16
|
+
*/
|
|
17
|
+
const account = starknetResponse
|
|
18
|
+
? starknetResponse.publicKey.toString()
|
|
19
|
+
: provider.publicKey.toString();
|
|
20
|
+
return {
|
|
21
|
+
accounts: [account],
|
|
22
|
+
chainId: CHAIN_ID,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function formatAccountsToCAIP(accounts: string[]) {
|
|
27
|
+
return accounts.map(
|
|
28
|
+
(account) =>
|
|
29
|
+
AccountId.format({
|
|
30
|
+
address: account.toString(),
|
|
31
|
+
chainId: {
|
|
32
|
+
namespace: CAIP_NAMESPACE,
|
|
33
|
+
reference: CAIP_STARKNET_CHAIN_ID,
|
|
34
|
+
},
|
|
35
|
+
}) as CaipAccount,
|
|
36
|
+
);
|
|
37
|
+
}
|