Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dpns js sdk fix for identity record rename #2001

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/js-dash-sdk/docs/platform/names/register.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ Parameters:
|----------------------------------|-----------|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **name** | String | yes | An alphanumeric (1-63 character) value used for human-identification (can contain `-` but not as the first or last character). If a name with no parent domain is entered, '.dash' is used. |
| **records** | Object | yes | records object having only one of the following items |
| **records.dashUniqueIdentityId** | String | no | Unique Identity ID for this name record |
| **records.dashAliasIdentityId** | String | no | Used to signify that this name is the alias for another id |
| **records.identity** | String | yes | Identity ID for this name record |
| **identity** | Identity | yes | A valid [registered identity](../identities/register.md) |


**Example**: `await client.platform.names.register('alice', { dashUniqueIdentityId: identity.getId() }, identity)`
**Example**: `await client.platform.names.register('alice', { identity: identity.getId() }, identity)`

Returns: the created domain document
4 changes: 2 additions & 2 deletions packages/js-dash-sdk/docs/platform/names/resolveByRecord.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ Parameters:

| parameters | type | required | Description |
|------------|-----------|----------------|----------------------------------------------------------------------|
| **record** | String | yes | Type of the record (`dashUniqueIdentityId` or `dashAliasIdentityId`) |
| **record** | String | yes | Type of the record (`identity`) |
| **value** | String | yes | Identifier value for the record |

**Example**:

This example will describe how to resolve names by the dash unique identity id.
```js
const identityId = '3ge4yjGinQDhxh2aVpyLTQaoka45BkijkoybfAkDepoN';
const document = await client.platform.names.resolveByRecord('dashUniqueIdentityId', identityId);
const document = await client.platform.names.resolveByRecord('identity', identityId);
```

Returns: array of ExtendedDocument.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('Platform', () => {
identityMock.getId.returns(identityId);

await register.call(platformMock, 'Dash', {
dashUniqueIdentityId: identityId,
identity: identityId,
}, identityMock);

expect(platformMock.documents.create.getCall(0).args[0]).to.deep.equal('dpns.preorder');
Expand All @@ -72,7 +72,7 @@ describe('Platform', () => {
normalizedParentDomainName: '',
preorderSalt: Buffer.alloc(32),
records: {
dashUniqueIdentityId: identityId,
identity: identityId,
},
subdomainRules: {
allowSubdomains: true,
Expand All @@ -86,7 +86,7 @@ describe('Platform', () => {
identityMock.getId.returns(identityId);

await register.call(platformMock, 'User.dash', {
dashAliasIdentityId: identityId,
identity: identityId,
}, identityMock);

expect(platformMock.documents.create.getCall(0).args[0]).to.deep.equal('dpns.preorder');
Expand All @@ -105,7 +105,7 @@ describe('Platform', () => {
normalizedParentDomainName: 'dash',
preorderSalt: Buffer.alloc(32),
records: {
dashAliasIdentityId: identityId,
identity: identityId,
},
subdomainRules: {
allowSubdomains: false,
Expand All @@ -119,7 +119,7 @@ describe('Platform', () => {

try {
await register.call(platformMock, 'user.dash', {
dashUniqueIdentityId: await generateRandomIdentifier(),
identity: await generateRandomIdentifier(),
}, identityMock);
} catch (e) {
expect(e.message).to.equal('DPNS is required to register a new name.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ const { hash } = require('@dashevo/wasm-dpp/lib/utils/hash');
* @param {Platform} this - bound instance class
* @param {string} name - name
* @param {Object} records - records object having only one of the following items
* @param {string} [records.dashUniqueIdentityId]
* @param {string} [records.dashAliasIdentityId]
* @param {string} [records.identity]
* @param identity - identity
*
* @returns registered domain document
Expand All @@ -21,8 +20,7 @@ export async function register(
this: Platform,
name: string,
records: {
dashUniqueIdentityId?: Identifier | string,
dashAliasIdentityId?: Identifier | string,
identity?: Identifier | string,
},
identity: {
getId(): Identifier;
Expand All @@ -31,12 +29,8 @@ export async function register(
): Promise<any> {
await this.initialize();

if (records.dashUniqueIdentityId) {
records.dashUniqueIdentityId = Identifier.from(records.dashUniqueIdentityId);
}

if (records.dashAliasIdentityId) {
records.dashAliasIdentityId = Identifier.from(records.dashAliasIdentityId);
if (records.identity) {
records.identity = Identifier.from(records.identity);
}

const nameLabels = name.split('.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Platform } from '../../Platform';
export async function resolveByRecord(this: Platform, record: string, value: any): Promise<any> {
await this.initialize();

if (record === 'dashUniqueIdentityId' || record === 'dashAliasIdentityId') {
if (record === 'identity') {
value = Identifier.from(value);
}

Expand Down
Loading