Skip to content

Commit

Permalink
test: add csca
Browse files Browse the repository at this point in the history
  • Loading branch information
danzipie committed Jul 3, 2024
1 parent bb79cad commit 86008dd
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions common/test/csca.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { assert, expect } from 'chai'
import path from "path";
import { getCSCAInputs } from "../src/utils/csca";
import { randomBytes } from 'crypto';
import forge from 'node-forge';
import { k_csca, k_dsc, max_cert_bytes, n_csca, n_dsc } from '../src/constants/constants';

describe("CSCA", function () {
const pem_csca = `-----BEGIN CERTIFICATE-----
MIIDCTCCAfGgAwIBAgIUVgXmIg3ZjJoGkQE2mwtKlcPI3bIwDQYJKoZIhvcNAQEF
BQAwFDESMBAGA1UEAwwJbW9ja19jc2NhMB4XDTI0MDYyODEzNDUzMFoXDTI1MDYy
ODEzNDUzMFowFDESMBAGA1UEAwwJbW9ja19jc2NhMIIBIjANBgkqhkiG9w0BAQEF
AAOCAQ8AMIIBCgKCAQEAmTkg9LzPdTsFgOL6uXHCGMylvo43XD5BpdION5nBFfx+
tKxC30AH41JAbJBb8kDY1FXQPfmE63ROfU0W9oMh8vu/n+yCJ22F4xqgOA012cXw
mEwa6A8dxeOqxv92dBdtN5XpcEne5FI1qzCCCRooQ5lMGikiGJiPVfXbIFPgVEv0
uW/bbmbNwmm3FZbWFKtotWIbfvLi14/9isk9Bgb1yYaiRhhr1AIyz6Whpsgxc+WE
GF8aOdmMzZWXouIyeaSr41R/PuXvOmkizg/YoJij4CDch42ofT/gtShP5k3uFa+G
NnmObx492pE7oEmtbJYi3ixuzx4tmnej+On40QBoSQIDAQABo1MwUTAdBgNVHQ4E
FgQUdTWxPLHwrq0uuqFF8jzGc1QPLOgwHwYDVR0jBBgwFoAUdTWxPLHwrq0uuqFF
8jzGc1QPLOgwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQUFAAOCAQEAlxot
U0kau1ukBqaaY8CrnxDYyW2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7SKl3XcaEjxJc
2FZ2oljdCaKkNKuBNKvfp9faf99WeGBdpcgFpdi01R5KuY5Nxla7mRX+Ui3nLr3o
liedieUn11Vg2XM73aoF7FrhM/DnLrgrd8fOfp6IPxXCK935m5F2Yp2v2xf7xlKo
rDIGzX44gmTYs3tlGdhf1+/zxXmY9KLNP/vdFze8SUYizlci/nRVOmxFkH20pWd5
0p9dgtebMBDmT7WB5mzfCqg8AOHxLDrl5s6AYya/MfvfnqunpOaBgd4+U1Z6ukx2
v7oH6bR2gKuuvX6Ceg6bqroNnT2kUwugyEafeZnLGPmLGUZrC7sJrBxerA==
-----END CERTIFICATE-----`;

it("should get csca input in devmode", async function () {
const devmod = true;
const dscSecret = randomBytes(31).toString('hex');
const dscCertificate = forge.pki.certificateFromPem(pem_dcs);
const cscaCertificate = forge.pki.certificateFromPem(pem_csca);

const csca = getCSCAInputs(dscSecret, dscCertificate, cscaCertificate, n_dsc, k_dsc, n_csca, k_csca, max_cert_bytes, true);

expect(csca).to.be.an("object");
expect(csca.siblings.length).to.be.equal(12);
expect(csca.siblings).deep.be.equal(
[
'1899628457317453197426768456858589983666227401303606152877725712904770786388',
'11850476168601990118767540453922551640834371441287882635558900147928082262216',
'6061080980122679361349022326493404370004932185085913345491175616560373782007',
'11286972368698509976183087595462810875513684078608517520839298933882497716792',
'3607627140608796879659380071776844901612302623152076817094415224584923813162',
'19712377064642672829441595136074946683621277828620209496774504837737984048981',
'20775607673010627194014556968476266066927294572720319469184847051418138353016',
'1126944913887516904289476884314188784817875835019645183711270186623300417204',
'10224931444631296256306111997023259115908040230658265780895445976301767844798',
'18616110284164381247048792467749872996052606923771839554448275315790271733321',
'12413880268183407374852357075976609371175688755676981206018884971008854919922',
'14271763308400718165336499097156975241954733520325982997864342600795471836726'
]
);
expect(csca.merkle_root).deep.be.equal(
['11406887179192998141316434121926377942525639172220901846038964800699077034561']);
expect(csca.dsc_modulus).deep.be.equal(
[
'2274452720635308011319510157240694683',
'1838153631168156821152860627617499540',
'1508236322282826252128237419135255738',
'154716275641845592459968062059861939',
'2551086069471860812627371667813190000',
'2036804671746015721457218685577363716',
'2197675407212041266152238818026660097',
'952559144234713328109310742637253150',
'1094810305529313628742540817651893415',
'2590122297445661660247681299457520286',
'857667800697748411815713990093100421',
'110844180922169487913807710181601982',
'924599447825126352366886626538782675',
'489153996513126344531655299188306352',
'1807067223405218119639469913104669186',
'2152071199403501416392165150654295407',
'4149310547746625546420145689385969'
]
);
});
});

0 comments on commit 86008dd

Please sign in to comment.