phantasma-sdk-ts 0.2.5 → 0.2.6
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/cjs/core/types/Carbon/Blockchain/Modules/Builders/TokenSchemasBuilder.js +20 -7
- package/dist/cjs/core/types/Ed25519Signature.js +4 -1
- package/dist/esm/core/types/Carbon/Blockchain/Modules/Builders/TokenSchemasBuilder.js +21 -8
- package/dist/esm/core/types/Ed25519Signature.js +5 -2
- package/dist/types/core/types/Carbon/Blockchain/Modules/Builders/TokenSchemasBuilder.d.ts.map +1 -1
- package/dist/types/core/types/Ed25519Signature.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -34,27 +34,40 @@ function parseTokenSchemasJson(json) {
|
|
|
34
34
|
exports.parseTokenSchemasJson = parseTokenSchemasJson;
|
|
35
35
|
class TokenSchemasBuilder {
|
|
36
36
|
static assertMetadataField(schemas, fieldTypes) {
|
|
37
|
-
|
|
37
|
+
for (const fieldType of fieldTypes) {
|
|
38
38
|
let fieldIsFound = false;
|
|
39
|
-
|
|
39
|
+
let caseMismatch = null;
|
|
40
|
+
for (const schema of schemas) {
|
|
40
41
|
const found = schema.fields.find(x => x.name.data === fieldType.name);
|
|
41
42
|
if (found != undefined) {
|
|
42
43
|
if (found.schema.type != fieldType.type) {
|
|
43
|
-
|
|
44
|
+
const actualType = VmType_1.VmType[found.schema.type] ?? found.schema.type;
|
|
45
|
+
const expectedType = VmType_1.VmType[fieldType.type] ?? fieldType.type;
|
|
46
|
+
return {
|
|
47
|
+
ok: false,
|
|
48
|
+
error: `Type mismatch for ${fieldType.name} field, must be ${actualType} instead of ${expectedType}`
|
|
49
|
+
};
|
|
44
50
|
}
|
|
45
51
|
fieldIsFound = true;
|
|
52
|
+
break;
|
|
46
53
|
}
|
|
47
|
-
|
|
54
|
+
if (!caseMismatch) {
|
|
48
55
|
const found2 = schema.fields.find(x => x.name.data.toLowerCase() === fieldType.name.toLowerCase());
|
|
49
56
|
if (found2 != undefined) {
|
|
50
|
-
|
|
57
|
+
caseMismatch = found2;
|
|
51
58
|
}
|
|
52
59
|
}
|
|
53
|
-
}
|
|
60
|
+
}
|
|
54
61
|
if (!fieldIsFound) {
|
|
62
|
+
if (caseMismatch) {
|
|
63
|
+
return {
|
|
64
|
+
ok: false,
|
|
65
|
+
error: `Case mismatch for ${fieldType.name} field, must be ${caseMismatch.name.data}`
|
|
66
|
+
};
|
|
67
|
+
}
|
|
55
68
|
return { ok: false, error: `Mandatory metadata field not found: ${fieldType.name}` };
|
|
56
69
|
}
|
|
57
|
-
}
|
|
70
|
+
}
|
|
58
71
|
return { ok: true, error: null };
|
|
59
72
|
}
|
|
60
73
|
static defaultSeriesSchema(sharedMetadata) {
|
|
@@ -24,7 +24,10 @@ class Ed25519Signature {
|
|
|
24
24
|
continue;
|
|
25
25
|
}
|
|
26
26
|
const pubKey = address.ToByteArray().slice(2);
|
|
27
|
-
|
|
27
|
+
const msgBytes = Buffer.from(message);
|
|
28
|
+
const sigHex = (0, utils_1.bytesToHex)(this.Bytes);
|
|
29
|
+
const pubKeyHex = (0, utils_1.bytesToHex)(pubKey);
|
|
30
|
+
if (ed25519.verify(msgBytes, sigHex, pubKeyHex)) {
|
|
28
31
|
return true;
|
|
29
32
|
}
|
|
30
33
|
}
|
|
@@ -2,7 +2,7 @@ import { bytesToHex } from '../../../../../utils';
|
|
|
2
2
|
import { CarbonBinaryWriter } from '../../../../CarbonSerialization';
|
|
3
3
|
import { VmNamedVariableSchema } from '../../Vm/VmNamedVariableSchema';
|
|
4
4
|
import { VmStructSchema } from '../../Vm/VmStructSchema';
|
|
5
|
-
import { vmTypeFromString } from '../../Vm/VmType';
|
|
5
|
+
import { vmTypeFromString, VmType } from '../../Vm/VmType';
|
|
6
6
|
import { TokenSchemas } from '../TokenSchemas';
|
|
7
7
|
import { nftDefaultMetadataFields, seriesDefaultMetadataFields, standardMetadataFields } from './MetadataHelper';
|
|
8
8
|
export class TokenSchemasJson {
|
|
@@ -29,27 +29,40 @@ export function parseTokenSchemasJson(json) {
|
|
|
29
29
|
}
|
|
30
30
|
export class TokenSchemasBuilder {
|
|
31
31
|
static assertMetadataField(schemas, fieldTypes) {
|
|
32
|
-
|
|
32
|
+
for (const fieldType of fieldTypes) {
|
|
33
33
|
let fieldIsFound = false;
|
|
34
|
-
|
|
34
|
+
let caseMismatch = null;
|
|
35
|
+
for (const schema of schemas) {
|
|
35
36
|
const found = schema.fields.find(x => x.name.data === fieldType.name);
|
|
36
37
|
if (found != undefined) {
|
|
37
38
|
if (found.schema.type != fieldType.type) {
|
|
38
|
-
|
|
39
|
+
const actualType = VmType[found.schema.type] ?? found.schema.type;
|
|
40
|
+
const expectedType = VmType[fieldType.type] ?? fieldType.type;
|
|
41
|
+
return {
|
|
42
|
+
ok: false,
|
|
43
|
+
error: `Type mismatch for ${fieldType.name} field, must be ${actualType} instead of ${expectedType}`
|
|
44
|
+
};
|
|
39
45
|
}
|
|
40
46
|
fieldIsFound = true;
|
|
47
|
+
break;
|
|
41
48
|
}
|
|
42
|
-
|
|
49
|
+
if (!caseMismatch) {
|
|
43
50
|
const found2 = schema.fields.find(x => x.name.data.toLowerCase() === fieldType.name.toLowerCase());
|
|
44
51
|
if (found2 != undefined) {
|
|
45
|
-
|
|
52
|
+
caseMismatch = found2;
|
|
46
53
|
}
|
|
47
54
|
}
|
|
48
|
-
}
|
|
55
|
+
}
|
|
49
56
|
if (!fieldIsFound) {
|
|
57
|
+
if (caseMismatch) {
|
|
58
|
+
return {
|
|
59
|
+
ok: false,
|
|
60
|
+
error: `Case mismatch for ${fieldType.name} field, must be ${caseMismatch.name.data}`
|
|
61
|
+
};
|
|
62
|
+
}
|
|
50
63
|
return { ok: false, error: `Mandatory metadata field not found: ${fieldType.name}` };
|
|
51
64
|
}
|
|
52
|
-
}
|
|
65
|
+
}
|
|
53
66
|
return { ok: true, error: null };
|
|
54
67
|
}
|
|
55
68
|
static defaultSeriesSchema(sharedMetadata) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SignatureKind } from '../interfaces/Signature';
|
|
2
2
|
import pkg from 'elliptic';
|
|
3
|
-
import { stringToUint8Array, bytesToHex
|
|
3
|
+
import { stringToUint8Array, bytesToHex } from '../utils';
|
|
4
4
|
import { PBinaryWriter } from './Extensions';
|
|
5
5
|
const { eddsa } = pkg;
|
|
6
6
|
const ed25519 = new eddsa('ed25519');
|
|
@@ -18,7 +18,10 @@ export class Ed25519Signature {
|
|
|
18
18
|
continue;
|
|
19
19
|
}
|
|
20
20
|
const pubKey = address.ToByteArray().slice(2);
|
|
21
|
-
|
|
21
|
+
const msgBytes = Buffer.from(message);
|
|
22
|
+
const sigHex = bytesToHex(this.Bytes);
|
|
23
|
+
const pubKeyHex = bytesToHex(pubKey);
|
|
24
|
+
if (ed25519.verify(msgBytes, sigHex, pubKeyHex)) {
|
|
22
25
|
return true;
|
|
23
26
|
}
|
|
24
27
|
}
|
package/dist/types/core/types/Carbon/Blockchain/Modules/Builders/TokenSchemasBuilder.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenSchemasBuilder.d.ts","sourceRoot":"","sources":["../../../../../../../../src/core/types/Carbon/Blockchain/Modules/Builders/TokenSchemasBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAiF,MAAM,kBAAkB,CAAC;AAE5H,qBAAa,gBAAgB;IAC3B,cAAc,EAAE,SAAS,EAAE,CAAC;IAC5B,GAAG,EAAE,SAAS,EAAE,CAAC;IACjB,GAAG,EAAE,SAAS,EAAE,CAAC;CAClB;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAkBpE;AAED,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,MAAM,CAAC,mBAAmB;
|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MAAM,EAAE,cAAc;CAGxC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Ed25519Signature.d.ts","sourceRoot":"","sources":["../../../../src/core/types/Ed25519Signature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI5D,qBAAa,gBAAiB,YAAW,SAAS;IACzC,KAAK,EAAE,UAAU,CAAC;IAClB,IAAI,EAAE,aAAa,CAAyB;gBAEvC,KAAK,CAAC,EAAE,UAAU;IAI9B,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO;IAI/C,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO;
|
|
1
|
+
{"version":3,"file":"Ed25519Signature.d.ts","sourceRoot":"","sources":["../../../../src/core/types/Ed25519Signature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI5D,qBAAa,gBAAiB,YAAW,SAAS;IACzC,KAAK,EAAE,UAAU,CAAC;IAClB,IAAI,EAAE,aAAa,CAAyB;gBAEvC,KAAK,CAAC,EAAE,UAAU;IAI9B,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO;IAI/C,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO;IAgBlE,aAAa,CAAC,MAAM,EAAE,aAAa;IAKnC,eAAe,CAAC,MAAM,EAAE,aAAa;IAI5C,WAAW,IAAI,UAAU;WAOX,QAAQ,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,GAAG,gBAAgB;CASjF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phantasma-sdk-ts",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.6",
|
|
4
|
+
"description": "Typescript SDK for interacting with the Phantasma Chain",
|
|
5
5
|
"author": "Phantasma Team",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
7
7
|
"module": "dist/esm/index.js",
|