@canton-network/dapp-sdk 0.1.0 → 0.1.2
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/README.md +18 -6
- package/dist/connect/index.d.ts +13 -0
- package/dist/connect/index.d.ts.map +1 -0
- package/dist/connect/index.js +65 -0
- package/dist/connect/listNetworks.d.ts +1 -0
- package/dist/connect/listNetworks.d.ts.map +1 -0
- package/dist/connect/listNetworks.js +1 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
# SDK
|
|
1
|
+
# DApp SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This SDK is for 3rd-party dApps developed against the Canton Network. It's intended to be used in a browser to securely connect users to Canton Network wallets. Once connected, the SDK provides a dApp UI permissions to read a user's selected Canton party and request transaction signatures.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The dApp SDK aims to adopt or follow Ethereum development conventions where possible, for example [eip-1193](https://eips.ethereum.org/EIPS/eip-1193).
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Installation
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
Install the SDK with your package manager of choice
|
|
10
|
+
|
|
11
|
+
```shell
|
|
12
|
+
$ npm install @canton-network/dapp-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
or
|
|
16
|
+
|
|
17
|
+
```shell
|
|
18
|
+
$ yarn add @canton-network/dapp-sdk
|
|
11
19
|
```
|
|
20
|
+
|
|
21
|
+
## Getting Started
|
|
22
|
+
|
|
23
|
+
Coming soon...
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as dappAPI from '@canton-network/core-wallet-dapp-rpc-client';
|
|
2
|
+
export * from '@canton-network/core-splice-provider';
|
|
3
|
+
export declare enum ErrorCode {
|
|
4
|
+
UserCancelled = 0,
|
|
5
|
+
Other = 1
|
|
6
|
+
}
|
|
7
|
+
export type ConnectError = {
|
|
8
|
+
status: 'error';
|
|
9
|
+
error: ErrorCode;
|
|
10
|
+
details: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function connect(): Promise<dappAPI.ConnectResult>;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connect/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,OAAO,MAAM,6CAA6C,CAAA;AAOtE,cAAc,sCAAsC,CAAA;AAqCpD,oBAAY,SAAS;IACjB,aAAa,IAAA;IACb,KAAK,IAAA;CACR;AAED,MAAM,MAAM,YAAY,GAAG;IACvB,MAAM,EAAE,OAAO,CAAA;IACf,KAAK,EAAE,SAAS,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,wBAAsB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CA+B9D"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { discover, popupHref } from '@canton-network/core-wallet-ui-components';
|
|
2
|
+
import { injectSpliceProvider, ProviderType, } from '@canton-network/core-splice-provider';
|
|
3
|
+
import * as storage from '../storage';
|
|
4
|
+
import { WalletEvent, } from '@canton-network/core-types';
|
|
5
|
+
export * from '@canton-network/core-splice-provider';
|
|
6
|
+
const injectProvider = ({ walletType, url }) => {
|
|
7
|
+
if (walletType === 'remote') {
|
|
8
|
+
return injectSpliceProvider(ProviderType.HTTP, new URL(url), storage.getKernelSession()?.sessionToken);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
return injectSpliceProvider(ProviderType.WINDOW);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
// On page load, restore and re-register the listener if needed
|
|
15
|
+
const discovery = storage.getKernelDiscovery();
|
|
16
|
+
if (discovery)
|
|
17
|
+
injectProvider(discovery);
|
|
18
|
+
const openKernelUserUI = (walletType, userUrl) => {
|
|
19
|
+
switch (walletType) {
|
|
20
|
+
case 'remote':
|
|
21
|
+
popupHref(new URL(userUrl));
|
|
22
|
+
break;
|
|
23
|
+
case 'extension': {
|
|
24
|
+
const msg = {
|
|
25
|
+
type: WalletEvent.SPLICE_WALLET_EXT_OPEN,
|
|
26
|
+
url: userUrl,
|
|
27
|
+
};
|
|
28
|
+
window.postMessage(msg, '*');
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
export var ErrorCode;
|
|
34
|
+
(function (ErrorCode) {
|
|
35
|
+
ErrorCode[ErrorCode["UserCancelled"] = 0] = "UserCancelled";
|
|
36
|
+
ErrorCode[ErrorCode["Other"] = 1] = "Other";
|
|
37
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
38
|
+
export async function connect() {
|
|
39
|
+
return discover()
|
|
40
|
+
.then(async (result) => {
|
|
41
|
+
// Store discovery result and remove previous session
|
|
42
|
+
storage.setKernelDiscovery(result);
|
|
43
|
+
storage.removeKernelSession();
|
|
44
|
+
const provider = injectProvider(result);
|
|
45
|
+
// Listen for connected event from the provider
|
|
46
|
+
// This will be triggered when the user connects to the wallet kernel
|
|
47
|
+
provider.on('onConnected', (event) => {
|
|
48
|
+
console.log('SDK: Store connection', event);
|
|
49
|
+
storage.setKernelSession(event);
|
|
50
|
+
});
|
|
51
|
+
const response = await provider.request({
|
|
52
|
+
method: 'connect',
|
|
53
|
+
});
|
|
54
|
+
if (!response.isConnected)
|
|
55
|
+
openKernelUserUI(result.walletType, response.userUrl);
|
|
56
|
+
return response;
|
|
57
|
+
})
|
|
58
|
+
.catch((err) => {
|
|
59
|
+
throw {
|
|
60
|
+
status: 'error',
|
|
61
|
+
error: ErrorCode.Other,
|
|
62
|
+
details: err instanceof Error ? err.message : String(err),
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=listNetworks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listNetworks.d.ts","sourceRoot":"","sources":["../../src/connect/listNetworks.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canton-network/dapp-sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"description": "Browser SDK for dApp development on the Canton Network",
|
|
6
|
-
"repository": "
|
|
6
|
+
"repository": "github:hyperledger-labs/splice-wallet-kernel",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"author": "Marc Juchli <marc.juchli@digitalasset.com>",
|
|
9
9
|
"main": "dist/index.js",
|
|
@@ -15,16 +15,16 @@
|
|
|
15
15
|
"test": "echo \"Warning: no test specified\""
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@canton-network/core-splice-provider": "^0.1.
|
|
19
|
-
"@canton-network/core-types": "^0.1.
|
|
18
|
+
"@canton-network/core-splice-provider": "^0.1.1",
|
|
19
|
+
"@canton-network/core-types": "^0.1.1",
|
|
20
20
|
"@canton-network/core-wallet-dapp-rpc-client": "^0.1.0",
|
|
21
|
-
"@canton-network/core-wallet-ui-components": "^0.1.
|
|
21
|
+
"@canton-network/core-wallet-ui-components": "^0.1.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"typescript": "^5.8.3"
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
|
-
"dist
|
|
27
|
+
"dist/**"
|
|
28
28
|
],
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|