Skip to content

Commit b7600ea

Browse files
Merge pull request #1183 from PolymeshAssociation/beta
Release v24
2 parents 2c78f6c + e888e4f commit b7600ea

File tree

105 files changed

+10981
-3541
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+10981
-3541
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2021 Polymath Inc.
189+
Copyright 2024 Verein Polymesh
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

+8-12
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@ This release is compatible with Polymesh v6.x.x
2424

2525
The Polymesh SDK's main goal is to provide external developers with a set of tools that will allow them to build powerful applications that interact with the Polymesh protocol. It focuses on abstracting away all the complexities of the Polymesh blockchain and expose a simple but complete interface. The result is a feature-rich, user-friendly node.js library.
2626

27-
### Before moving on
28-
29-
This document assumes you are already familiar with [Security Tokens](https://thesecuritytokenstandard.org/) in general and [Polymath](https://www.polymath.network/) as well as [Polymesh](https://polymath.network/polymesh) in particular.
30-
3127
### Technical Pre-requisites
3228

33-
In order to use the Polymath SDK, you must install [node](https://nodejs.org/) \(version 16\) and [npm](https://www.npmjs.com/). The library is written in [typescript](https://www.typescriptlang.org/), but can also be used in plain javascript. This document will assume you are using typescript, but the translation to javascript is very simple.
29+
In order to use the Polymesh SDK, you must install [node](https://nodejs.org/) \(version 16\) and [npm](https://www.npmjs.com/). The library is written in [typescript](https://www.typescriptlang.org/), but can also be used in plain javascript. This document will assume you are using typescript, but the translation to javascript is very simple.
3430

3531
### Documentation
3632

@@ -71,8 +67,8 @@ async function run() {
7167
mnemonic: '//Alice', //A "well known" mnemonic, often with sudo privileges on development chains
7268
},
7369
{
74-
mnemonic: 'forest end mail art wish leave truth else ignore royal knife river' // most mnemonics are 12 words
75-
}
70+
mnemonic: 'forest end mail art wish leave truth else ignore royal knife river', // most mnemonics are 12 words
71+
},
7672
],
7773
});
7874
const polyClient = await Polymesh.connect({
@@ -133,11 +129,11 @@ Creating transactions is a two-step process. First a procedure is created, which
133129
The SDK exposes getter functions that will return entities, which may have their own functions:
134130

135131
```typescript
136-
const assetsPage = await polyClient.assets.get({ size: new BigNumber(20) })
137-
const asset = assetsPage.data[0]
132+
const assetsPage = await polyClient.assets.get({ size: new BigNumber(20) });
133+
const asset = assetsPage.data[0];
138134

139-
const assetDetails = await asset.details()
140-
console.log('asset details:', assetDetails)
135+
const assetDetails = await asset.details();
136+
console.log('asset details:', assetDetails);
141137
```
142138

143139
Note: Some getters require "middleware" to be configured, which is a chain indexer that aids in historical queries. All such methods will have a comment indicating this requirement.
@@ -148,4 +144,4 @@ The SDK uses the class `Account` as an abstraction for a public/private key pair
148144

149145
The only thing an `Account` holds is the POLYX utility token. Ownership of any asset on the Polymesh chain requires an `Identity`. This process involves a trusted provider writing a claim to the chain, stating that this person has completed a "customer due diligence" (CDD) process. For development chains, the mnemonic `//Alice` can create CDD claims by default.
150146

151-
Polymesh uses an `Identity` to provide flexibility in managing permissions. Portfolios can be created, and secondary keys can be granted permission to provide fine grained authorization.
147+
Polymesh uses an `Identity` to provide flexibility in managing permissions. Portfolios can be created, and secondary keys can be granted permission to provide fine grained authorization.

SECURITY.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Do not open issues that might have security implications! It is critical that se
66

77
Vulnerabilities can be reported by emailing repository admins:
88

9-
- Víctor Vicente victor@polymath.network
10-
- Eric Richardson ericrichardson@polymath.network
11-
- Prashant Bajpai prashant@polymath.network
9+
- Víctor Vicente victor@polymesh.network
10+
- Eric Richardson eric@polymesh.network
11+
- Prashant Bajpai prashant@polymesh.network
1212

1313
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
1414

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@
5555
"@polkadot/dev-ts": "^0.76.22",
5656
"@polkadot/typegen": "10.9.1",
5757
"@polymeshassociation/local-signing-manager": "^3.0.1",
58+
"@polymeshassociation/polymesh-types": "^5.9.1",
5859
"@polymeshassociation/signing-manager-types": "^3.0.0",
59-
"@polymeshassociation/typedoc-theme": "^1.1.0",
60+
"@polymeshassociation/typedoc-theme": "^1.2.0",
6061
"@semantic-release/changelog": "^6.0.1",
6162
"@types/bluebird": "^3.5.38",
6263
"@types/jest": "29.5.4",
@@ -102,9 +103,9 @@
102103
"tsconfig-paths": "^4.2.0",
103104
"tsconfig-paths-webpack-plugin": "^4.1.0",
104105
"ttypescript": "1.5.15",
105-
"typedoc": "0.23.5",
106+
"typedoc": "0.24.8",
106107
"typedoc-github-wiki-theme": "^1.0.1",
107-
"typedoc-plugin-markdown": "3.13.2",
108+
"typedoc-plugin-markdown": "3.17.1",
108109
"typescript": "4.6.2",
109110
"webpack": "^5.88.2",
110111
"webpack-cli": "^5.1.4",

scripts/fetchDefinitions.js

+15-16
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/* eslint-disable */
2-
const http = require('http');
32
const path = require('path');
43
const fs = require('fs');
54
const rimraf = require('rimraf');
65
const util = require('util');
76
const { forEach, camelCase, mapKeys } = require('lodash');
8-
const { NODE_URL, SCHEMA_PORT } = require('./consts');
7+
8+
const { typesBundle } = require('@polymeshassociation/polymesh-types');
9+
const types = require('@polymeshassociation/polymesh-types/types/6.1.x.json');
910

1011
const definitionsDir = path.resolve('src', 'polkadot');
1112
const typesDir = path.resolve(definitionsDir, 'polymesh');
@@ -111,17 +112,15 @@ function writeDefinitions(schemaObj) {
111112
fs.writeFileSync(path.resolve(definitionsDir, 'definitions.ts'), defExports);
112113
}
113114

114-
http.get(`http://${NODE_URL}:${SCHEMA_PORT}/polymesh_schema.json`, res => {
115-
const chunks = [];
116-
res.on('data', chunk => {
117-
chunks.push(chunk);
118-
});
119-
120-
res.on('end', () => {
121-
const schema = Buffer.concat(chunks);
122-
const schemaObj = JSON.parse(schema);
123-
transformSchema(schemaObj);
124-
125-
writeDefinitions(schemaObj);
126-
});
127-
});
115+
(() => {
116+
const { rpc, runtime, signedExtensions } = typesBundle.spec.polymesh_dev;
117+
const schema = {
118+
types,
119+
rpc,
120+
runtime,
121+
signedExtensions,
122+
};
123+
124+
transformSchema(schema);
125+
writeDefinitions(schema);
126+
})();

scripts/transactions.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,9 @@
256256
"exempt_ticker_affirmation": "exempt_ticker_affirmation",
257257
"remove_ticker_affirmation_exemption": "remove_ticker_affirmation_exemption",
258258
"pre_approve_ticker": "pre_approve_ticker",
259-
"remove_ticker_pre_approval": "remove_ticker_pre_approval"
259+
"remove_ticker_pre_approval": "remove_ticker_pre_approval",
260+
"add_mandatory_mediators": "add_mandatory_mediators",
261+
"remove_mandatory_mediators": "remove_mandatory_mediators"
260262
},
261263
"CapitalDistribution": {
262264
"distribute": "distribute",
@@ -387,7 +389,12 @@
387389
"affirm_with_receipts_with_count": "affirm_with_receipts_with_count",
388390
"affirm_instruction_with_count": "affirm_instruction_with_count",
389391
"reject_instruction_with_count": "reject_instruction_with_count",
390-
"withdraw_affirmation_with_count": "withdraw_affirmation_with_count"
392+
"withdraw_affirmation_with_count": "withdraw_affirmation_with_count",
393+
"add_instruction_with_mediators": "add_instruction_with_mediators",
394+
"add_and_affirm_with_mediators": "add_and_affirm_with_mediators",
395+
"affirm_instruction_as_mediator": "affirm_instruction_as_mediator",
396+
"withdraw_affirmation_as_mediator": "withdraw_affirmation_as_mediator",
397+
"reject_instruction_as_mediator": "reject_instruction_as_mediator"
391398
},
392399
"Statistics": {
393400
"add_transfer_manager": "add_transfer_manager",

sdk-docs-typedoc.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
],
1313
"entryPointStrategy": "expand",
1414
"out": "sdk-docs",
15+
"plugin": ["@polymeshassociation/typedoc-theme", "typedoc-plugin-markdown"],
1516
"theme": "polymesh-docs",
1617
"exclude": [
1718
"src/internal.ts",

src/api/client/Assets.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,7 @@ export class Assets {
274274
*
275275
* @note supports pagination
276276
*/
277-
public async get(
278-
paginationOpts?: PaginationOptions
279-
): Promise<ResultSet<FungibleAsset | NftCollection>> {
277+
public async get(paginationOpts?: PaginationOptions): Promise<ResultSet<Asset>> {
280278
const {
281279
context: {
282280
polymeshApi: {

src/api/client/Claims.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export class Claims {
213213
trustedClaimIssuers: trustedClaimIssuers?.map(trustedClaimIssuer =>
214214
signerToString(trustedClaimIssuer)
215215
),
216-
claimTypes: claimTypes?.map(ct => ClaimTypeEnum[ct]),
216+
claimTypes: Array.isArray(claimTypes) ? claimTypes.map(ct => ClaimTypeEnum[ct]) : undefined,
217217
includeExpired,
218218
};
219219

src/api/client/Identities.ts

+84-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { createPortfolioTransformer } from '~/api/entities/Venue';
22
import {
3+
allowIdentityToCreatePortfolios,
4+
AllowIdentityToCreatePortfoliosParams,
35
attestPrimaryKeyRotation,
46
AuthorizationRequest,
57
ChildIdentity,
@@ -9,6 +11,8 @@ import {
911
Identity,
1012
NumberedPortfolio,
1113
registerIdentity,
14+
revokeIdentityToCreatePortfolios,
15+
RevokeIdentityToCreatePortfoliosParams,
1216
rotatePrimaryKey,
1317
} from '~/internal';
1418
import {
@@ -18,7 +22,8 @@ import {
1822
RegisterIdentityParams,
1923
RotatePrimaryKeyParams,
2024
} from '~/types';
21-
import { asIdentity, createProcedureMethod } from '~/utils/internal';
25+
import { identityIdToString } from '~/utils/conversion';
26+
import { asIdentity, assertIdentityExists, createProcedureMethod } from '~/utils/internal';
2227

2328
/**
2429
* Handles all Identity related functionality
@@ -47,17 +52,12 @@ export class Identities {
4752
context
4853
);
4954

50-
this.createPortfolio = createProcedureMethod<
51-
{ name: string },
52-
{ names: string[] },
53-
NumberedPortfolio[],
54-
NumberedPortfolio
55-
>(
55+
this.createPortfolio = createProcedureMethod(
5656
{
5757
getProcedureAndArgs: args => [
5858
createPortfolios,
5959
{
60-
names: [args.name],
60+
portfolios: [{ name: args.name, ownerDid: args.ownerDid }],
6161
},
6262
],
6363
transformer: createPortfolioTransformer,
@@ -67,7 +67,10 @@ export class Identities {
6767

6868
this.createPortfolios = createProcedureMethod(
6969
{
70-
getProcedureAndArgs: args => [createPortfolios, args],
70+
getProcedureAndArgs: args => [
71+
createPortfolios,
72+
{ portfolios: args.names.map(name => ({ name, ownerDid: args.ownerDid })) },
73+
],
7174
},
7275
context
7376
);
@@ -78,6 +81,16 @@ export class Identities {
7881
},
7982
context
8083
);
84+
85+
this.allowIdentityToCreatePortfolios = createProcedureMethod(
86+
{ getProcedureAndArgs: args => [allowIdentityToCreatePortfolios, args] },
87+
context
88+
);
89+
90+
this.revokeIdentityToCreatePortfolios = createProcedureMethod(
91+
{ getProcedureAndArgs: args => [revokeIdentityToCreatePortfolios, args] },
92+
context
93+
);
8194
}
8295

8396
/**
@@ -120,13 +133,22 @@ export class Identities {
120133

121134
/**
122135
* Create a new Portfolio under the ownership of the signing Identity
136+
* @note the `ownerDid` is optional. If provided portfolios will be created as Custody Portfolios under the `ownerDid`
123137
*/
124-
public createPortfolio: ProcedureMethod<{ name: string }, NumberedPortfolio[], NumberedPortfolio>;
138+
public createPortfolio: ProcedureMethod<
139+
{ name: string; ownerDid?: string },
140+
NumberedPortfolio[],
141+
NumberedPortfolio
142+
>;
125143

126144
/**
127145
* Creates a set of new Portfolios under the ownership of the signing Identity
146+
* @note the `ownerDid` is optional. If provided portfolios will be created as Custody Portfolios under the `ownerDid`
128147
*/
129-
public createPortfolios: ProcedureMethod<{ names: string[] }, NumberedPortfolio[]>;
148+
public createPortfolios: ProcedureMethod<
149+
{ names: string[]; ownerDid?: string },
150+
NumberedPortfolio[]
151+
>;
130152

131153
/**
132154
* Create an Identity instance from a DID
@@ -165,4 +187,55 @@ export class Identities {
165187
* - the signing Identity is already a child of some other identity
166188
*/
167189
public createChild: ProcedureMethod<CreateChildIdentityParams, ChildIdentity>;
190+
191+
/**
192+
* Gives permission to the Identity to create Portfolios on behalf of the signing Identity
193+
*
194+
* @throws if
195+
* - the provided Identity already has permissions to create portfolios for signing Identity
196+
* - the provided Identity does not exist
197+
*/
198+
public allowIdentityToCreatePortfolios: ProcedureMethod<
199+
AllowIdentityToCreatePortfoliosParams,
200+
void
201+
>;
202+
203+
/**
204+
* Revokes permission from the Identity to create Portfolios on behalf of the signing Identity
205+
*
206+
* @throws if
207+
* - the provided Identity already does not have permissions to create portfolios for signing Identity
208+
* - the provided Identity does not exist
209+
*/
210+
public revokeIdentityToCreatePortfolios: ProcedureMethod<
211+
RevokeIdentityToCreatePortfoliosParams,
212+
void
213+
>;
214+
215+
/**
216+
* Returns a list of allowed custodian did(s) for Identity
217+
* @throws if
218+
* - the provided Identity does not exist
219+
*/
220+
public async getAllowedCustodians(did: string | Identity): Promise<string[]> {
221+
const {
222+
context: {
223+
polymeshApi: { query },
224+
},
225+
} = this;
226+
227+
const identity = asIdentity(did, this.context);
228+
229+
await assertIdentityExists(identity);
230+
231+
const custodians = await query.portfolio.allowedCustodians.entries(did.toString());
232+
233+
return custodians.map(([storageKey]) => {
234+
const {
235+
args: [, custodianIdentityId],
236+
} = storageKey;
237+
238+
return identityIdToString(custodianIdentityId);
239+
});
240+
}
168241
}

0 commit comments

Comments
 (0)